内容部分先不用管,我这边只是做个测试,过几天会讲这些的,先忽略

np.zeros(tuple)

import numpy as nphelp(np.zeros)Help on built-in function zeros in module numpy.core.multiarray:
zeros(...)
zeros(shape, dtype=float, order='C')
Return a new array of given shape and type, filled with zeros.
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.
See Also
--------
zeros_like : Return an array of zeros with shape and type of input.
ones_like : Return an array of ones with shape and type of input.
empty_like : Return an empty array with shape and type of input.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.
Examples
--------
>>> np.zeros(5)
array([ 0., 0., 0., 0., 0.])
>>> np.zeros((5,), dtype=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.]])
>>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
array([(0, 0), (0, 0)],
dtype=[('x', '<i4'), ('y', '<i4')])# 一维
np.zeros(5) # 完整写法:np.zeros((5,))array([0., 0., 0., 0., 0.])# 可以指定类型
np.zeros(5,dtype=int)array([0, 0, 0, 0, 0])# 二维
np.zeros((2,5))array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]])# 三维 ==> 可以这么理解,2个2*5(2行5列)的矩阵
np.zeros((2,2,5))array([[[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]],
[[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]]])################### 扩展部分 ######################### 建议用元组,官方文档都是元组,而且shape返回类型就是元组
array1 = np.zeros([2,3])
print(array1)
type(array1)
print(array1.shape) # shape返回类型就是元组[[0. 0. 0.]
[0. 0. 0.]]
(2, 3)np.ones(tuple) 用法和 np.zeros(tuple)差不多

help(np.ones)Help on function ones in module numpy.core.numeric:
ones(shape, dtype=None, order='C')
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.
See Also
--------
zeros, ones_like
Examples
--------
>>> np.ones(5)
array([ 1., 1., 1., 1., 1.])
>>> np.ones((5,), dtype=int)
array([1, 1, 1, 1, 1])
>>> np.ones((2, 1))
array([[ 1.],
[ 1.]])
>>> s = (2,2)
>>> np.ones(s)
array([[ 1., 1.],
[ 1., 1.]])# 一维
np.ones(5) # 完整写法 np.ones((5,))array([1., 1., 1., 1., 1.])# 可以指定类型
np.ones(5,dtype=int)array([1, 1, 1, 1, 1])# 二维,传一个shape元组
np.ones((2,5))array([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]])# 三维 可以理解为两个二维数组
np.ones((2,2,5))array([[[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]],
[[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]]])先普及一个数学基础:任何 矩阵 x 单位矩阵 都等于其 本身
单位矩阵是个方阵,从左上角到右下角的对角线(称为主对角线)上的元素均为1。其他全都为0,eg:

用 np.eye() 来定义(eye:眼睛)
扩展: np.eye(rows,columns=rows)
help(np.eye)Help on function eye in module numpy.lib.twodim_base:
eye(N, M=None, k=0, dtype=<class 'float'>, order='C')
Return a 2-D array with ones on the diagonal and zeros elsewhere.
Parameters
----------
N : int
Number of rows in the output.
M : int, optional
Number of columns in the output. If None, defaults to `N`.
k : int, optional
Index of the diagonal: 0 (the default) refers to the main diagonal,
a positive value refers to an upper diagonal, and a negative value
to a lower diagonal.
dtype : data-type, optional
Data-type of the returned array.
order : {'C', 'F'}, optional
Whether the output should be stored in row-major (C-style) or
column-major (Fortran-style) order in memory.
.. versionadded:: 1.14.0
Returns
-------
I : ndarray of shape (N,M)
An array where all elements are equal to zero, except for the `k`-th
diagonal, whose values are equal to one.
See Also
--------
identity : (almost) equivalent function
diag : diagonal 2-D array from a 1-D array specified by the user.
Examples
--------
>>> np.eye(2, dtype=int)
array([[1, 0],
[0, 1]])
>>> np.eye(3, k=1)
array([[ 0., 1., 0.],
[ 0., 0., 1.],
[ 0., 0., 0.]])# 定义一个2行的单位矩阵(列默认和行一致)
np.eye(2)array([[1., 0.],
[0., 1.]])np.eye(3,dtype=int)array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])# 定义一个5行5列的单位矩阵
np.eye(5)array([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])