官术网_书友最值得收藏!

NumPy array

NumPy allows the creation of n-dimensional arrays, which is where the name of the data type, numpy.ndarraycomes 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])
主站蜘蛛池模板: 天津市| 社旗县| 得荣县| 兴海县| 高密市| 德清县| 承德县| 钟山县| 娄烦县| 雅江县| 辽源市| 应城市| 体育| 崇义县| 闻喜县| 蓝山县| 江城| 永康市| 凌云县| 利川市| 岗巴县| 介休市| 尚志市| 昌邑市| 凤凰县| 南溪县| 西和县| 抚松县| 额济纳旗| 孟州市| 罗甸县| 武定县| 巴楚县| 饶河县| 惠水县| 梅州市| 太康县| 平度市| 烟台市| 泗阳县| 孟连|