Python Numpy
This is wonderful, but one feature is missing.
When analyzing data, you'll often want to carry out operations over entire collections of values, and you want to do this fast. With lists, this is a problem.
Let's consider we have two lists
If you now want to calculate the Body Mass Index for each family member, you'd hope that this call can work, making the calculations element-wise.
Unfortunately, Python throws an error, because it has no idea how to do calculations with lists.
You could solve this by going through each list element one after the other, and calculating the BMI for each person separately, but this is terribly inefficient and tiresome to write.
A way more elegant solution is to use NumPy, or Numeric Python. It's a Python package that, among others, provides an alternative to the regular python list: the Numpy array.
It's really easy, and super-fast as well.
Next, these regular lists were converted to Numpy arrays. The same operations now work without any problem: Numpy knows how to work with arrays as if they are single values
If you do try to create an array with different types, like this for example, the resulting Numpy array will contain a single type, string in this case. The boolean and the float were both converted to strings.
Second, you should know that a Numpy array is simply a new kind of Python type, like the float, string and list types from before
Take this Python list and this numpy array, for example:
- · The Numpy Package provides the array, a data type that can be used to do element-wise calculations.
- · Because Numpy arrays can only hold element of a single type, calculations on Numpy arrays can be carried out way faster than regular Python lists.