numpy函数解析

numpy.memmap

首先看numpy的官方网站的介绍:

class numpy.memmap

       create a memory-map to an array stored in a binary file on disk.

       Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory. Numpy's memmap's are array-like objects. This differs from Python's mmap module, which uses file-like objects.

创建一个内存-映射到数组并存储在硬盘上的二进制文件。这个内存-映射文件用来访问在硬盘上的大文件的一小部分数据,而不用讲整个文件读取到内存中。Numpy的memmap是数组类型的对象,这有别于Python的mmap模块,它是文件类型的对象。

numpy.diff

numpy.diff(a, n=1,axis=-1)

        Calculate the n-th order discrete difference along given axis.

        The first order difference is given by out[n]=a[n+1]-a[n] along the given axis, higher order differences are calculated by using diff recursively.

就是一个进行查分的函数,可以指定n来决定是几度查分。

numpy.arange

numpy.arange([start,]stop,[step,]dtype=none)

        Return evenly spaced values within a given interval.

类似于Python自带的arang()函数,只不过返回的是一个数组。

numpy.reshape

numpy.reshape(a, newshape, order='C')

        newshape: int or tuple or ints

        The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In  this case, the value is inferred from the length of the array and remaining dimensions.
简单理解就是把一个矩阵变换维度,比如矩阵有12个数,可以变成1行12列的矩阵,也可以变成2行6列的矩阵,同样也可以变成3行4列的矩阵。其中的newshape为一个整数或者元组。其中的一个形状维度可以为-1,在这种情况下,最终的变换矩阵由另一个维度值与矩阵中元素的个数来决定。
numpy.mean
numpy.mean(a, axis=None, dtype=None, out=None, keepdims=False)
       Compute the arithmetic mean along the specified axis.
       Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64intermediate and return values are used for integer inputs.
返回矩阵指定坐标轴的算术平均值。其中axis=0,求得结果是在横坐标上的平均值;axis=1,求得结果是在纵坐标上的平均值。
numpy.sqrt
numpy.sqrt(x[, out])
       Return the positive square-root of an array, element-wise.
>>> np.sqrt([1,4,9])
array([ 1., 2., 3.])
numpy.vectorize
numpy.vectorize(pyfunc, otypes='')
    Generalized function class.
    Define a vectorized function which takes a nested sequence of objects or numpy arrays inputs and returns a numpy array as output. The vectorized function evaluates pyfunc over successive tuples of the input arrays like the python map function, except it uses the broadcasting rules of numpy.
    The data type of the output of vectorized is determined by calling the function with the first element of the input. The can be avoided by specifying the otypes argument.
简单来说,这个函数的功能很类似于map这个函数,其中的pyfunc函数是你真正需要处理事情的函数,我们可以叫它core函数。vectorize将元组的每一个元素作用在core函数中,然后返回core函数处理后的结果。

numpy.array

numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
   Create an array.
object: array_like
An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence.
dtype: data-type, optional
The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. This argument can only be used to 'upcast' the array. For downcasting, use the .astype(t) method.

该函数有两个参数,array_like,即一个数组,dtype,表示数组中元素类型的对象。

numpy.asarray

numpy.asarray(a)

将输入a转化为一个矩阵。输入数据a可以为任何转化为矩阵的类型,包括列表,元组的列表,元组,元组的元组,列表的元组等。

numpy.empty

numpy.empty(shape, dtype=float, order='C')

返回一个指定shape和type的矩阵,矩阵元素未进行初始化。

numpy.vstack

numpy.vstack(tup)

将矩阵依次垂直地放到一个栈中(row wise)

将一系列矩阵垂直放到栈中生成一个单一的矩阵。  


你可能感兴趣的:(Python相关)