- Matplotlib for Python Developers
- Aldrin Yim Claire Chung Allen Yu
- 203字
- 2021-08-27 18:48:19
NumPy array
NumPy allows the creation of n-dimensional arrays, which is where the name of the data type, numpy.ndarray, comes from. It handles many sophisticated scientific and matrix operations. It provides many linear algebra and random number functionalities.
NumPy lies at the core of many calculations that computationally enable Matplotlib and many other Python packages. It is therefore a dependency for many common packages and often comes along with Python distributions. For instance, it provides the fundamental data structure for SciPy, a package that handles statistical calculations useful in science and many other areas.
To import NumPy, input this:
import numpy as np
To create a NumPy array from lists, use the following:
x = np.array([2,3,1,0])
You can also create non-integral arithmetic series with NumPy by using np.linspace(start,stop,number).
See the following example:
In [1]: np.linspace(3,5,20) Out[1]: array([ 3. , 3.10526316, 3.21052632, 3.31578947, 3.42105263, 3.52631579, 3.63157895, 3.73684211, 3.84210526, 3.94736842, 4.05263158, 4.15789474, 4.26315789, 4.36842105, 4.47368421, 4.57894737, 4.68421053, 4.78947368, 4.89473684, 5. ])
Matrix operations can be applied across NumPy arrays. Here is an example of multiplying two arrays:
In [2]: a = np.array([1, 2, 1])
In [3]: b = np.array([2, 3, 8])
In [4]: a*b
Out[4]: array([2, 6, 8])
- R語言數(shù)據(jù)分析從入門到精通
- Objective-C應(yīng)用開發(fā)全程實(shí)錄
- Cocos2d-x游戲開發(fā):手把手教你Lua語言的編程方法
- Microsoft Dynamics 365 Extensions Cookbook
- Python從菜鳥到高手(第2版)
- Mastering OpenCV 4
- 編譯系統(tǒng)透視:圖解編譯原理
- MongoDB權(quán)威指南(第3版)
- Learning Python by Building Games
- JavaScript:Moving to ES2015
- 劍指大數(shù)據(jù):企業(yè)級(jí)數(shù)據(jù)倉庫項(xiàng)目實(shí)戰(zhàn)(在線教育版)
- jQuery炫酷應(yīng)用實(shí)例集錦
- Image Processing with ImageJ
- ASP.NET求職寶典
- 愛上C語言:C KISS