Numpy
learning Numpy
harry_tea
这个作者很懒,什么都没留下…
展开
-
numpy数组操作
本文目录拼接拼接concatenate((a1, a2...), axis=0)将数组序列进行拼接a = np.array([[1, 2], [3, 4]])b = np.array([[5, 6]])np.concatenate((a, b), axis=0) # 按行拼接np.concatenate((a, b.T), axis=1) # 按列拼接np.concatenate((a, b), axis=None) # flatten'''array([[1, 2],原创 2022-01-11 21:18:58 · 347 阅读 · 0 评论 -
np.resize
numpy.resize(a, new_shape)a:要被resize的数组new_shape:被resize的大小,int或者tuple类型返回一个特定形状的数组Return a new array with the specified shape.If the new array is larger than the original array, then the new array is filled with repeated copies of a. Note that thi原创 2021-11-20 16:25:50 · 7800 阅读 · 0 评论 -
np.linalg
本文目录np.linalg.invnp.linalg.normnp.linalg.invnp.linalg.inv(a)计算一个矩阵的逆Compute the (multiplicative) inverse of a matrix.Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a) = eye(a.shape[0]).import numpy as npfrom nu原创 2021-10-29 20:31:09 · 739 阅读 · 0 评论 -
np.argsort
np.argsort(a, axis=-1, kind=None, order=None)a:arrayaxis:需要排列的维度,默认为-1,即最后一维度;如果axis为None,将array展开为一维注意:numpy的维度是倒着数的,比如array有4维,(m, n, p, q),那么q为第一维,编号为0,p为第二维,编号为1,以此类推返回数组从小到大的索引Returns the indices that would sort an array.Perform an indirect s原创 2021-10-27 21:26:01 · 258 阅读 · 0 评论 -
np.random
本文目录np.random1. np.random.choicenp.random1. np.random.choicenp.random.choice(a, size=None, replace=True, p=None)a:一维array(tuple or dic)或者int;如果是int采样集合为np.arange即[0,1,2,...,a−1][0, 1, 2, ... , a-1][0,1,2,...,a−1]szie:int或者tuple,int表示采样几个值,tuple表示采样出来原创 2021-10-27 12:28:46 · 221 阅读 · 0 评论 -
np.flatnonzero
numpy.flatnonzero(a)a:输入array返回:一个数组,该数组是a的非0索引该函数输入一个矩阵,返回array的非0索引(也可以指定索引元素,下面会展示)Return indices that are non-zero in the flattened version of a.import numpy as npx = np.arange(-2 ,3)print(x)y = np.flatnonzero(x)print(y)y_ = x[np.flatnon原创 2021-10-27 00:00:20 · 740 阅读 · 0 评论