先上numpy方法导图
array常用属性
属性 | 介绍 |
---|---|
ndarray.flags | 关于数组的存储信息 |
ndarray.shape | 数组维度信息的元组 |
ndarray.strides | 在遍历数组时 的每个维度的步长 |
ndarray.ndim | 数组的维度数 |
ndarray.data | 指向数组数据开头的缓存对象 |
ndarray.size | 数组元素的总个数 |
ndarray.itemsize | 一个数组元素的长度(以字节为单位) |
ndarray.nbytes | 查看数组占内存大小 |
ndarray.base | 如果内存来自其他对象,则为基础对象。 |
一些其他属性
属性 | 介绍 |
---|---|
ndarray.T | 转置 |
ndarray.real | 提取数组实数部分 |
ndarray.imag | 数组虚数部分 |
ndarray.flat | 一维数组迭代器 |
ndarray.ctypes | 使用ctypes模块简化数组对象 |
数组方法
数组转换
方法 | 介绍 |
---|---|
ndarray.item(*args) | 复制一个数组的元素并返回常规类型数据 |
ndarray.tolist() | 将数组转换为列表 |
ndarray.itemset(*args) | 插入数组 |
ndarray.tostring([order]) | 尽可能转换成字符串 |
ndarray.tobytes([order]) | 将数组转成字节 |
ndarray.tofile(fid[, sep, format] | 以文本或二进制写入 |
ndarray.dump(file) | 读取文件 |
ndarray.dumps() | 返回一个数组的字符串形式 |
ndarray.astype(dtype[, order, casting, …]) | 复制数组转换为指定的类型 |
ndarray.byteswap([inplace]) | Swap the bytes of the array elements |
ndarray.copy([order]) | 复制数组 |
ndarray.view([dtype][, type]) | 查看数据 |
ndarray.getfield(dtype[, offset]) | 返回数组的实数部分 |
ndarray.setflags([write, align, uic]) | Set array flags WRITEABLE, ALIGNED, (WRITEBACKIFCOPY and UPDATEIFCOPY), respectively. |
ndarray.fill(value) | 填充 |
Shape manipulation形状操作
方法 | 介绍 |
---|---|
ndarray.reshape(shape[, order]) | 重新整合形状(保持原有的数据) |
ndarray.resize(new_shape[, refcheck]) | 自定义shape,会丢失数据,或以零填充数据 |
ndarray.transpose(*axes) | 沿着轴转置,对于D维的转置:请看详情 |
ndarray.swapaxes(axis1, axis2) | 返回交换后的数组 |
ndarray.flatten([order]) | 将数组整合成一维 |
ndarray.ravel([order]) | 将数组整合成一维 |
ndarray.squeeze([axis]) | 移除掉某一维,这一维必须要求为1 |
Item selection and manipulation(Item选择和操作)
方法 | 介绍 |
---|---|
ndarray.take(indices[, axis, out, mode]) | A call such as np.take(arr, indices, axis=3) is equivalent to arr[:,:,:,indices,...] |
ndarray.put(indices, values[, mode]) | a.flat[n] = values[n] |
ndarray.repeat(repeats[, axis]) | 复制数组 |
ndarray.choose(choices[, out, mode]) | 选择索引复制 |
ndarray.sort([axis, kind, order]) | 排序 |
ndarray.argsort([axis, kind, order]) | 返回排序后的索引下标 |
ndarray.partition(kth[, axis, kind, order]) | 还搞不懂排序规则 |