np.zeros用法小结
来源:互联网 发布:java 编程思想pdf下载 编辑:程序博客网 时间:2024/05/29 10:07
np.zeros用法
numpy.zeros(shape, dtype=float, order=’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.
Examples
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.]])
np.zeros((2,2))
array([[ 0., 0.],
[ 0., 0.]])
np.zeros((2,), dtype=[(‘x’, ‘i4’), (‘y’, ‘i4’)]) # custom dtype
array([(0, 0), (0, 0)],
dtype=[(‘x’, ‘
>>>y = np.zeros((2,3,4))array([[[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.]], [[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.]]]) y.ndim = 3
结果是一个大矩阵,这个大矩阵有2行1列,每行有一个3×4的小矩阵组成。
>>> y = np.zeros((3,4,2),int)array([[[0, 0], [0, 0], [0, 0], [0, 0]], [[0, 0], [0, 0], [0, 0], [0, 0]], [[0, 0], [0, 0], [0, 0], [0, 0]]]) y.ndim = 3
结果是一个大矩阵,这个大矩阵有3行1列,每行有一个4×2的小矩阵组成。
>>> y = np.zeros((3,2,2,2),int)array([[[[0, 0], [0, 0]], [[0, 0], [0, 0]]], [[[0, 0], [0, 0]], [[0, 0], [0, 0]]], [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]])>>> y.ndim = 4
这类矩阵要从后往前看,也就是先生成了一个2*2*的矩阵,再把这个小矩阵向下复制一次生成*4*2的矩阵,最后一个3是把刚才生成的矩阵再向下复制3次,也就是3个4*2矩阵的叠加。
- np.zeros用法小结
- np.zeros()思考
- numpy.zeros(np.zeros)使用方法--python学习笔记31
- numpy库函数:zeros用法
- ones,zeros,size用法总结
- python中py.zeros 用法
- Zeros()
- zeros
- np.newaxis的用法
- P NP NPC问题小结
- python中ones zeros 的用法
- 如何用python编写一个绘制马赛克图像的自写程序mask = np.zeros
- matlab中zeros 和 ones 这两个函数的用法
- matlab zeros函数、ones函数、size函数用法
- matlab 中ones、zeros和prod函数的用法
- NP
- np
- NP
- C#中webservice接受数组参数
- weasyprint 生成发票pdf文件
- 统计学习方法笔记(一)概论
- oracle练习5
- 关于中断的碎碎念
- np.zeros用法小结
- ConcurrentHashMap原理分析
- 第十二课记录 HBase的Java编程接口
- jsp利用自定义标签制作精美的分页标签
- Linux+.NetCore+Nginx搭建集群
- UESTC1057 (线段树裸题)
- 51nod 1066
- B6AC使用说明
- scikit-learn实现线性回归之LinearRegression模型