numpy.zeros方法中的此参数是什么意思? [英] What does this parameter in numpy.zeros method mean?
问题描述
我有这段代码,发现很难理解以如下所示的方式定义numpy.zeros
方法的优点.
I have this piece of code and I am finding it difficult to understand what is advantage of defining the numpy.zeros
method the way it is as shown below.
Z = np.zeros((10,10), [('x',float),('y',float)])
Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,10),
np.linspace(0,1,10))
print(Z)
提及x
和y
的意义是什么?
推荐答案
输出的秘密在numpy.linspace(0,1,10)
,输出一个numpy.array,其内容为:
The secret of the output is at numpy.linspace(0,1,10)
, outputs an numpy.array, with:
[ 0. 0.11111111 0.22222222 0.33333333 0.44444444 0.55555556
0.66666667 0.77777778 0.88888889 1. ]
对于'x'
形状,对于'y'
,其中'0'
是起点,'1'
是终点,具有10
样本.
For 'x'
shape, as for 'y'
, where '0'
is where it starts, '1'
is where is stops, with 10
samples.
numpy.zeros()
正在为"ij"索引定义矩阵形状(M,N),其中M = N = 10
The numpy.zeros()
are defining a matrix shape (M, N) for ‘ij’ indexing, where M = N = 10
numpy.meshgrid()
将linspace
结果的值索引到矩阵中,例如 ai,aj
The numpy.meshgrid()
indexes into the matrix the values of linspace
results, like ai, aj
例如
Z = np.zeros((10,10), [('x',int),('y',int)])
Z['x'], Z['y'] = np.meshgrid( np.linspace(0,10,10), np.linspace(0,10,10))
print Z
输出:
[[(0, 0) (1, 0) (2, 0) (3, 0) (4, 0) (5, 0) (6, 0) (7, 0) (8, 0) (10, 0)]
[(0, 1) (1, 1) (2, 1) (3, 1) (4, 1) (5, 1) (6, 1) (7, 1) (8, 1) (10, 1)]
[(0, 2) (1, 2) (2, 2) (3, 2) (4, 2) (5, 2) (6, 2) (7, 2) (8, 2) (10, 2)]
[(0, 3) (1, 3) (2, 3) (3, 3) (4, 3) (5, 3) (6, 3) (7, 3) (8, 3) (10, 3)]
[(0, 4) (1, 4) (2, 4) (3, 4) (4, 4) (5, 4) (6, 4) (7, 4) (8, 4) (10, 4)]
[(0, 5) (1, 5) (2, 5) (3, 5) (4, 5) (5, 5) (6, 5) (7, 5) (8, 5) (10, 5)]
[(0, 6) (1, 6) (2, 6) (3, 6) (4, 6) (5, 6) (6, 6) (7, 6) (8, 6) (10, 6)]
[(0, 7) (1, 7) (2, 7) (3, 7) (4, 7) (5, 7) (6, 7) (7, 7) (8, 7) (10, 7)]
[(0, 8) (1, 8) (2, 8) (3, 8) (4, 8) (5, 8) (6, 8) (7, 8) (8, 8) (10, 8)]
[(0, 10) (1, 10) (2, 10) (3, 10) (4, 10) (5, 10) (6, 10) (7, 10) (8, 10)
(10, 10)]]
输出矩阵ij
标量.
检查下一个网址:
- numpy.linspace()
- numpy.zeros()
- numpy.meshgrid()
这篇关于numpy.zeros方法中的此参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!