numpy的属性和函数

NumPy的主要对象是同种元素的多维数组。这是一个所有的元素都是一种类型、通过一个正整数元组索引的元素表格(通常是元素是数字)。在NumPy中维度(dimensions)叫做轴(axes),轴的个数叫做秩(rank)。

例如,在3D空间一个点的坐标[1, 2, 3]是一个秩为1的数组,因为它只有一个轴。那个轴长度为3.又例如,在以下例子中,数组的秩为2(它有两个维度).第一个维度长度为2,第二个维度长度为3.
[[ 1., 0., 0.],
[ 0., 1., 2.]]
NumPy的数组类被称作ndarray。通常被称作数组。注意numpy.array和标准Python库类array.array并不相同,后者只处理一维数组和提供少量功能。更多重要ndarray对象属性有:
ndarray.ndim数组轴的个数,在python的世界中,轴的个数被称作秩
ndarray.shape数组的维度。这是一个指示数组在每个维度上大小的整数元组。例如一个n排m列的矩阵,它的shape属性将是(2,3),这个元组的长度显然是秩,即维度或者ndim属性
ndarray.size数组元素的总个数,等于shape属性中元组元素的乘积。
ndarray.dtype一个用来描述数组中元素类型的对象,可以通过创造或指定dtype使用标准Python类型。另外NumPy提供它自己的数据类型。
ndarray.itemsize数组中每个元素的字节大小。例如,一个元素类型为float64的数组itemsiz属性值为8(=64/8),又如,一个元素类型为complex32的数组item属性为4(=32/8).

ndarray.data包含实际数组元素的缓冲区,通常我们不需要使用这个属性,因为我们总是通过索引来使用数组中的元素。
数组ndarray
NumPy最重要的一个特点就是其N维数组对象(即ndarray),该对象是一个快速而灵活的大数据集容器,该对象由两部分组成:
实际的数据;
描述这些数据的元数据;
常用ndarray属性:
dtype 描述数组元素的类型
shape 以tuple表示的数组形状
ndim 数组的维度
size 数组中元素的个数
itemsize 数组中的元素在内存所占字节数
T 数组的转置
flat 返回一个数组的迭代器,对flat赋值将导致整个数组的元素被覆盖
real/imag 给出复数数组的实部/虚部
nbytes 数组占用的存储空间
常用ndarray方法:
reshape(…) 返回一个给定shape的数组的副本
resize(…) 返回给定shape的数组,原数组shape发生改变
flatten()/ravel() 返回展平数组,原数组不改变
astype(dtype) 返回指定元素类型的数组副本
fill() 将数组元素全部设定为一个标量值
sum/Prod() 计算所有数组元素的和/积
mean()/var()/std() 返回数组元素的均值/方差/标准差
max()/min()/ptp()/median() 返回数组元素的最大值/最小值/取值范围/中位数
argmax()/argmin() 返回最大值/最小值的索引
sort() 对数组进行排序,axis指定排序的轴;kind指定排序算法,默认是快速排序
view()/copy() view创造一个新的数组对象指向同一数据;copy是深复制
tolist() 将数组完全转为列表,注意与直接使用list(array)的区别
compress() 返回满足条件的元素构成的数组

numpy的其他函数或属性:
‘atleast_2d’,
‘atleast_3d’,
‘average’,
‘bartlett’,
‘base_repr’,
‘bench’,
‘binary_repr’,
‘bincount’,
‘bitwise_and’,
‘bitwise_not’,
‘bitwise_or’,
‘bitwise_xor’,
‘blackman’,
‘block’,
‘bmat’,
‘bool’,
‘bool8’,
‘bool_’,
‘broadcast’,
‘broadcast_arrays’,
‘broadcast_to’,
‘busday_count’,
‘busday_offset’,
‘busdaycalendar’,
‘byte’,
‘byte_bounds’,
‘bytes0’,
‘bytes_’,
‘c_’,
‘can_cast’,
‘cast’,
‘cbrt’,
‘cdouble’,
‘ceil’,
‘cfloat’,
‘char’,
‘character’,
‘chararray’,
‘choose’,
‘clip’,
‘clongdouble’,
‘clongfloat’,
‘column_stack’,
‘common_type’,
‘compare_chararrays’,
‘compat’,
‘complex’,
‘complex128’,
‘complex64’,
‘complex_’,
‘complexfloating’,
‘compress’,
‘concatenate’,
‘conj’,
‘conjugate’,
‘convolve’,
‘copy’,
‘copysign’,
‘copyto’,
‘core’,
‘corrcoef’,
‘correlate’,
‘cos’,
‘cosh’,
‘count_nonzero’,
‘cov’,
‘cross’,
‘csingle’,
‘ctypeslib’,
‘cumprod’,
‘cumproduct’,
‘cumsum’,
‘datetime64’,
‘datetime_as_string’,
‘datetime_data’,
‘deg2rad’,
‘degrees’,
‘delete’,
‘deprecate’,
‘deprecate_with_doc’,
‘diag’,
‘diag_indices’,
‘diag_indices_from’,
‘diagflat’,
‘diagonal’,
‘diff’,
‘digitize’,
‘disp’,
‘divide’,
‘division’,
‘divmod’,
‘dot’,
‘double’,
‘dsplit’,
‘dstack’,
‘dtype’,
‘dual’,
‘e’,
‘ediff1d’,
‘einsum’,
‘einsum_path’,
‘emath’,
‘empty’,
‘empty_like’,
‘equal’,
‘errstate’,
‘euler_gamma’,
‘exp’,
‘exp2’,
‘expand_dims’,
‘expm1’,
‘extract’,
‘eye’,
‘fabs’,
‘fastCopyAndTranspose’,
‘fft’,
‘fill_diagonal’,
‘find_common_type’,
‘finfo’,
‘fix’,
‘flatiter’,
‘flatnonzero’,
‘flexible’,
‘flip’,
‘fliplr’,
‘flipud’,
‘float’,
‘float16’,
‘float32’,
‘float64’,
‘float_’,
‘float_power’,
‘floating’,
‘floor’,
‘floor_divide’,
‘fmax’,
‘fmin’,
‘fmod’,
‘format_parser’,
‘frexp’,
‘frombuffer’,
‘fromfile’,
‘fromfunction’,
‘fromiter’,
‘frompyfunc’,
‘fromregex’,
‘fromstring’,
‘full’,
‘full_like’,
‘fv’,
‘generic’,
‘genfromtxt’,
‘geomspace’,
‘get_array_wrap’,
‘get_include’,
‘get_printoptions’,
‘getbufsize’,
‘geterr’,
‘geterrcall’,
‘geterrobj’,
‘gradient’,
‘greater’,
‘greater_equal’,
‘half’,
‘hamming’,
‘hanning’,
‘heaviside’,
‘histogram’,
‘histogram2d’,
‘histogramdd’,
‘hsplit’,
‘hstack’,
‘hypot’,
‘i0’,
‘identity’,
‘iinfo’,
‘imag’,
‘in1d’,
‘index_exp’,
‘indices’,
‘inexact’,
‘inf’,
‘info’,
‘infty’,
‘inner’,
‘insert’,
‘int’,
‘int0’,
‘int16’,
‘int32’,
‘int64’,
‘int8’,
‘int_’,
‘int_asbuffer’,
‘intc’,
‘integer’,
‘interp’,
‘intersect1d’,
‘intp’,
‘invert’,
‘ipmt’,
‘irr’,
‘is_busday’,
‘isclose’,
‘iscomplex’,
‘iscomplexobj’,
‘isfinite’,
‘isfortran’,
‘isin’,
‘isinf’,
‘isnan’,
‘isnat’,
‘isneginf’,
‘isposinf’,
‘isreal’,
‘isrealobj’,
‘isscalar’,
‘issctype’,
‘issubclass_’,
‘issubdtype’,
‘issubsctype’,
‘iterable’,
‘ix_’,
‘kaiser’,
‘kron’,
‘ldexp’,
‘left_shift’,
‘less’,
‘less_equal’,
‘lexsort’,
‘lib’,
‘linalg’,
‘linspace’,
‘little_endian’,
‘load’,
‘loads’,
‘loadtxt’,
‘log’,
‘log10’,
‘log1p’,
‘log2’,
‘logaddexp’,
‘logaddexp2’,
‘logical_and’,
‘logical_not’,
‘logical_or’,
‘logical_xor’,
‘logspace’,
‘long’,
‘longcomplex’,
‘longdouble’,
‘longfloat’,
‘longlong’,
‘lookfor’,
‘ma’,
‘mafromtxt’,
‘mask_indices’,
‘mat’,
‘math’,
‘matlib’,
‘matmul’,
‘matrix’,
‘matrixlib’,
‘max’,
‘maximum’,
‘maximum_sctype’,
‘may_share_memory’,
‘mean’,
‘median’,
‘memmap’,
‘meshgrid’,
‘mgrid’,
‘min’,
‘min_scalar_type’,
‘minimum’,
‘mintypecode’,
‘mirr’,
‘mod’,
‘modf’,
‘moveaxis’,
‘msort’,
‘multiply’,
‘nan’,
‘nan_to_num’,
‘nanargmax’,
‘nanargmin’,
‘nancumprod’,
‘nancumsum’,
‘nanmax’,
‘nanmean’,
‘nanmedian’,
‘nanmin’,
‘nanpercentile’,
‘nanprod’,
‘nanstd’,
‘nansum’,
‘nanvar’,
‘nbytes’,
‘ndarray’,
‘ndenumerate’,
‘ndfromtxt’,
‘ndim’,
‘ndindex’,
‘nditer’,
‘negative’,
‘nested_iters’,
‘newaxis’,
‘nextafter’,
‘nonzero’,
‘not_equal’,
‘nper’,
‘npv’,
‘numarray’,
‘number’,
‘obj2sctype’,
‘object’,
‘object0’,
‘object_’,
‘ogrid’,
‘oldnumeric’,
‘ones’,
‘ones_like’,
‘outer’,
‘packbits’,
‘pad’,
‘partition’,
‘percentile’,
‘pi’,
‘piecewise’,
‘pkgload’,
‘place’,
‘pmt’,
‘poly’,
‘poly1d’,
‘polyadd’,
‘polyder’,
‘polydiv’,
‘polyfit’,
‘polyint’,
‘polymul’,
‘polynomial’,
‘polysub’,
‘polyval’,
‘positive’,
‘power’,
‘ppmt’,
‘print_function’,
‘prod’,
‘product’,
‘promote_types’,
‘ptp’,
‘put’,
‘putmask’,
‘pv’,
‘r_’,
‘rad2deg’,
‘radians’,
‘random’,
‘rank’,
‘rate’,
‘ravel’,
‘ravel_multi_index’,
‘real’,
‘real_if_close’,
‘rec’,
‘recarray’,
‘recfromcsv’,
‘recfromtxt’,
‘reciprocal’,
‘record’,
‘remainder’,
‘repeat’,
‘require’,
‘reshape’,
‘resize’,
‘result_type’,
‘right_shift’,
‘rint’,
‘roll’,
‘rollaxis’,
‘roots’,
‘rot90’,
‘round’,
‘round_’,
‘row_stack’,
‘s_’,
‘safe_eval’,
‘save’,
‘savetxt’,
‘savez’,
‘savez_compressed’,
‘sctype2char’,
‘sctypeDict’,
‘sctypeNA’,
‘sctypes’,
‘searchsorted’,
‘select’,
‘set_numeric_ops’,
‘set_printoptions’,
‘set_string_function’,
‘setbufsize’,
‘setdiff1d’,
‘seterr’,
‘seterrcall’,
‘seterrobj’,
‘setxor1d’,
‘shape’,
‘shares_memory’,
‘short’,
‘show_config’,
‘sign’,
‘signbit’,
‘signedinteger’,
‘sin’,
‘sinc’,
‘single’,
‘singlecomplex’,
‘sinh’,
‘size’,
‘sometrue’,
‘sort’,
‘sort_complex’,
‘source’,
‘spacing’,
‘split’,
‘sqrt’,
‘square’,
‘squeeze’,
‘stack’,
‘std’,
‘str’,
‘str0’,
‘str_’,
‘string_’,
‘subtract’,
‘sum’,
‘swapaxes’,
‘sys’,
‘take’,
‘tan’,
‘tanh’,
‘tensordot’,
‘test’,
‘testing’,
‘tile’,
‘timedelta64’,
‘trace’,
‘tracemalloc_domain’,
‘transpose’,
‘trapz’,
‘tri’,
‘tril’,
‘tril_indices’,
‘tril_indices_from’,
‘trim_zeros’,
‘triu’,
‘triu_indices’,
‘triu_indices_from’,
‘true_divide’,
‘trunc’,
‘typeDict’,
‘typeNA’,
‘typecodes’,
‘typename’,
‘ubyte’,
‘ufunc’,
‘uint’,
‘uint0’,
‘uint16’,
‘uint32’,
‘uint64’,
‘uint8’,
‘uintc’,
‘uintp’,
‘ulonglong’,
‘unicode’,
‘unicode_’,
‘union1d’,
‘unique’,
‘unpackbits’,
‘unravel_index’,
‘unsignedinteger’,
‘unwrap’,
‘ushort’,
‘vander’,
‘var’,
‘vdot’,
‘vectorize’,
‘version’,
‘void’,
‘void0’,
‘vsplit’,
‘vstack’,
‘warnings’,
‘where’,
‘who’,
‘zeros’,
‘zeros_like’

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值