标签:
Numpy is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation.
At the core of the NumPy package, is the ndarray object. It keep homogeneous(同质的) data types.There are several important differences between NumPy arrays and the standard Python sequences:
Vectorization(向量化) and Broadcasting(广播):
(1)向量化:更简明易读、更短的代码意味着更少的错误、更接近标准数学符号、more "Pythonic"
(2)广播:统一相同尺寸。
Numpy’s
array class is called ndarray.
It is also known by the alias array.
Note that numpy.array is
not the same as the Standard Python Library classarray.array,
which only handles one-dimensional arrays and offers less functionality.
The
more important attributes of an ndarray object
are:
(1) ndarray.ndim : the number of axes
(2) ndarray.shape : For example (n,m)
(3) ndarray.size : the total elements, equal to n *m...
(4) ndarray.dtype : the type of the ele. One can create or specify dtype‘s using standard Python types.
(5) ndarray.itemsize : the ele‘s bytes, For example float64 has itemsize 8(64/8)
(6) ndarray.data : the buffer containing the actual ele of the array.(一般不用此属性,我们用索引)
(1) you
can create an array from a regular Python list or tuple using the array function.
(2) array transforms sequences of sequences into two-dimensional arrays,
array transforms
sequences of sequences of sequences into three-dimensional arrays.
(3) The type of the array can also be explicitly specified at creation.
(4) When the eles are originally unknown, but its size is known. Numpy create it with placeholder(占位符).
The function zeros creates
an array full of zeros.
The function ones creates
an array full of ones.
The function empty creates
an array whose initial content is random and depends on the state of the memory.
By default, the dtype of the created array is float64.
(5) To create sequences of numbersn, Numpyt use arange(Just like range) and linspace.
NumPy displays it in a similar way to nested lists, but with the following layout:
Bidimensionals(二维的) as matrices.
Tridimensionals(三维的)
as lists of matrices.
If
an array is too large to be printed, NumPy automatically skips the central part.
To
disable this behaviour and force NumPy to print the entire array, using set_print options.
(2)
Unlike in many matrix languages, * is elementwise(元素乘).
The
matrix product(矩阵乘) can be performed using the dot function
or method:
(3) Some operations, such as += and *=, act in place to modify an existing array rather than create a new one.
(4)
When operating with arrays of different types, using upcasting(向上转型).
(5) Many unary operations,are implemented as methods of the ndarray class.
(6) by specifying(指明) the axis parameter you can apply an operation along the specified axis of an array:
Within
NumPy, these functions operate ele:
See also
all, any, apply_along_axis, argmax, argmin, argsort, average, bincount, ceil,clip, conj, corrcoef, cov, cross, cumprod, cumsum, diff, dot, floor, inner, inv,lexsort, max, maximum, mean, median, min, minimum, nonzero, outer, prod,re, round, sort, std, sum, trace, transpose, var, vdot, vectorize, where
numpy module 1 -- Numpy tutorial
标签:
原文地址:http://blog.csdn.net/nicesimon7/article/details/51885746