Numpy.Zeros等

来源:互联网 发布:手机淘宝退货流程图 编辑:程序博客网 时间:2024/05/22 05:17

numpy.zeros

numpy.zeros(shapedtype=floatorder='C')

Parameters:

shape : int or sequence of ints

Shape of the new array, e.g., (2, 3) or 2.

dtype : data-type, optional

The desired data-type for the array, e.g., numpy.int8. Default is numpy.float64.

order : {‘C’, ‘F’}, optional

Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory.

Returns:

out : ndarray

Array of zeros with the given shape, dtype, and order.

Return a new array of given shape and type, filled with zeros

例:

1,np.zeros((3, 5), dtype=np.uint8)
输出:

[[0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0]]

2,np.zeros(2, dtype=np.uint8)输出:
[0 0]
类似的还有

numpy.ones

numpy.ones(shapedtype=Noneorder='C')[source]

Return a new array of given shape and type, filled with ones.

Parameters:

shape : int or sequence of ints

Shape of the new array, e.g., (2, 3) or 2.

dtype : data-type, optional

The desired data-type for the array, e.g., numpy.int8. Default is numpy.float64.

order : {‘C’, ‘F’}, optional

Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory.

Returns:

out : ndarray

Array of ones with the given shape, dtype, and order.

原创粉丝点击