numpy 构建一个全为零的数组 zeros()方法
python构建指定长度全为零的数组numpy.zeros( )语法:numpy.zeros(shape, dtype=float, order='C')返回一个指定类型和格式的数组的全为0的数组示例:指定长度的一维数组>>> np.zeros(5)array([ 0.,0.,0.,0.,0.])指定数据类型,指定长度的一维数组>>> np.zeros((5), d
·
python构建指定长度全为零的数组
numpy.zeros( )
语法:
numpy.zeros(shape, dtype=float, order='C')
返回一个指定类型和格式的数组的全为0的数组
示例:
- 指定长度的一维数组
>>> np.zeros(5)
array([ 0., 0., 0., 0., 0.])
- 指定数据类型,指定长度的一维数组
>>> np.zeros((5), dtype=np.int)
array([0, 0, 0, 0, 0])
- 二维数组
>>> np.zeros((2, 1))
array([[ 0.],
[ 0.]])
>>> s = (2,2)
>>> np.zeros(s)
array([[ 0., 0.],
[ 0., 0.]])
- 指定dtype
>>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
array([(0, 0), (0, 0)],
dtype=[('x', '<i4'), ('y', '<i4')])
更多推荐
已为社区贡献1条内容
所有评论(0)