如何用Python创建一个全为零的数组?
- 内容介绍
- 文章标签
- 相关推荐
本文共计610个文字,预计阅读时间需要3分钟。
使用numpy.zeros函数创建零矩阵:参数说明:- shape:整数或整数序列,表示生成的新数组的形状,如(2, 3)或2。- dtype:生成数组的元素数据类型,如numpy.int8。默认为numpy.float64。
语句格式:
numpy.zeros(shape, dtype=float, order='C')
参数说明:
shape:整型或元素为整型的序列,表示生成的新数组的shape,如(2,3)或 2。
dtype:生成数组的数据格式,如numpy.int8。默认为numpy.float64。
order:{'C', 'F'}可选,是否将多维数据存储为C-或Fortran-contiguous(按行或按列)顺序。
返回值:ndarray,一个指定了shape, dtype, order的零数组。
示例见下:
第四个例子看起来很方便。
本文共计610个文字,预计阅读时间需要3分钟。
使用numpy.zeros函数创建零矩阵:参数说明:- shape:整数或整数序列,表示生成的新数组的形状,如(2, 3)或2。- dtype:生成数组的元素数据类型,如numpy.int8。默认为numpy.float64。
语句格式:
numpy.zeros(shape, dtype=float, order='C')
参数说明:
shape:整型或元素为整型的序列,表示生成的新数组的shape,如(2,3)或 2。
dtype:生成数组的数据格式,如numpy.int8。默认为numpy.float64。
order:{'C', 'F'}可选,是否将多维数据存储为C-或Fortran-contiguous(按行或按列)顺序。
返回值:ndarray,一个指定了shape, dtype, order的零数组。
示例见下:
第四个例子看起来很方便。

