What is NumPy?
NumPy (short for numerical Python) is an open source Python library for scientific computing. It lets you work with arrays and matrices in a natural way.
In a way, NumPy replaces some of the functionality of MATLAB and Mathematica, allowing rapid interactive prototyping.
NumPy code is much cleaner than straight Python code and it tries to accomplish the same tasks. NumPy's arrays are stored more efficiently than an equivalent data structure in base Python, such as a list of lists.
Large portions of NumPy are written in C. This makes NumPy faster than pure Python code.
The drawback of NumPy arrays is that they are more specialized than plain lists. Outside the context of numerical computations, NumPy arrays are less useful.
If you are a Java programmer, you might be interested in Jython, the Java implementation of Python. In that case, I have bad news for you. Unfortunately, Jython runs on the Java Virtual Machine and cannot access NumPy because NumPy's modules are mostly written in C.
>>> import numpy as np
>>> a = np.arange(3) ** 2
>>> b = np.arange(3) ** 3
>>> a + b
array([ 0, 2, 12], dtype=int32)
>>> print(a+b)
[ 0 2 12]
注意结果没有逗号隔开!
Obviously, we are not dealing with a Python list but with a NumPy array. NumPy arrays are specialized data structures for numerical data.