Numpy.Zeros等

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.

你可能感兴趣的:(学习笔记,NumPy)