junxnone / examples

some code/notebook examples
0 stars 0 forks source link

numpy - usecase #17

Open junxnone opened 6 years ago

junxnone commented 6 years ago

Simple UseCase

UseCase Code
numpy.ndarray nan 替换为 0 data[np.isnan(data)] = 0
统计 array 值分布 np.bincount(data)

numpy.load

Load arrays or pickled objects from .npy, .npz or pickled files.

numpy.save

numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)

从任何暴露数组接口的对象,或从返回数组的任何方法创建一个ndarray。

参数 描述
object  任何暴露数组接口方法的对象都会返回一个数组或任何(嵌套)序列。
dtype  数组的所需数据类型,可选。
copy  可选,默认为true,对象是否被复制。
order  C(按行)、F(按列)或A(任意,默认)。
subok  默认情况下,返回的数组被强制为基类数组。 如果为true,则返回子类。
ndimin  指定返回数组的最小维数。

return ndarray: An array object satisfying the specified requirements.\

reference https://www.yiibai.com/numpy/numpy_ndarray_object.html

ndarray.max(axis=None, out=None)

Return the maximum of an array or maximum along an axis. 求ndarray中指定维度的最大值,默认求所有值的最大值

numpy.amax(a, axis=None, out=None, keepdims=False)

Parameters Description
a array_like, Input data.
axis None or int or tuple of ints, optional Axis or axes along which to operate. By default, flattened input is used. If this is a tuple of ints, the maximum is selected over multiple axes, instead of a single axis or all the axes as before.
out ndarray, optional Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output. See doc.ufuncs (Section “Output arguments”) for more details.
keepdims bool, optional If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.

return amax : ndarray or scalar Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.

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

返回特定大小,以 0 填充的新数组。

序号 参数 描述
1 Shape  空数组的形状,整数或整数元组
2 Dtype  所需的输出数组类型,可选
3 Order  'C'为按行的 C 风格数组,'F'为按列的 Fortran 风格数组

return ndarray: Array of zeros with the given shape, dtype, and order.

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

这个函数返回ndarray对象,包含给定范围内的等间隔值。

序号 参数 描述
1 start  范围的起始值,默认为0
2 stop  范围的终止值(不包含)
3 step  两个值的间隔,默认为1
4 dtype  返回ndarray的数据类型,如果没有提供,则会使用输入数据的类型。

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

不改变数据的条件下修改形状

参数 描述
a 要修改形状的数组
newshape 整数或者整数数组,新的形状应当兼容原有形状
order 'C'为 C 风格顺序,'F'为 F 风格顺序,'A'为保留原顺序。

return reshaped_array : ndarray , This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.

numpy.atleast_1d(*arys)

Convert inputs to arrays with at least one dimension.

numpy.expand_dims(a, axis)

函数通过在指定位置插入新的轴来扩展数组形状。

参数 描述
a 输入数组
axis 新轴插入的位置
junxnone commented 4 years ago

9