numpy.zeros()函数是最重要的函数之一,广泛用于机器学习程序中。此函数用于生成包含零的数组。
numpy.zeros()函数提供给定形状和类型的新数组,并用零填充。
链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-zeros.html
来源:LearnFk无涯教程网
numpy.zeros(shape, dtype=float, order='C'
shape:整数或整数元组(int or tuple of ints)
此参数用于定义数组的尺寸。此参数用于我们要在其中创建数组的形状,例如(3,2)或2。
dtype:data-type(可选)
此参数用于定义数组的所需数据类型。默认情况下,数据类型为numpy.float64。该参数对于定义不是必需的。
order:{'C','F'}(可选)
此参数用于定义我们要在内存中存储数据的顺序,即行主要(C样式)或列主要(Fortran样式)
此函数返回一个ndarray。输出数组是具有指定形状,dtype,order并包含零的数组。
import numpy as np a=np.zeros(6) a
输出:
array([0., 0., 0., 0., 0., 0.])
在上面的代码中
在输出中,显示了带有浮点整数(零)的数组。
import numpy as np a=np.zeros((6,), dtype=int) a
输出:
array([0, 0, 0, 0, 0, 0])
import numpy as np a=np.zeros((6,2)) a
输出:
array([[0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.], [0., 0.]])
在上面的代码中
在输出中,已显示给定形状的数组。
Import numpy as np s1=(3,2) a=np.zeros(s1) a
输出:
array([[0., 0.], [0., 0.], [0., 0.]])
Import numpy as np a=np.zeros((3,), dtype=[('x', 'i4'), ('y', 'i4')]) a
输出:
array([(0, 0), (0, 0), (0, 0)], dtype=[('x', '<i4'), ('y', '<i4')])
在上面的代码中
在输出中,已显示包含自定义数据类型的零的数组。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕