.shape[] 在使用 Matplotlib 的“for i in range(Y.shape[0])”中有什么作用?
shape属性通常用于获取数组的当前形状,但它也可用于通过为数组分配数组维度的元组来就地重塑数组。
脚步
使用np.array方法获取数组Y。
Y.shape将返回一个元组(4,)。
Y.shape[0]方法将返回4,即元组的第一个元素。
示例
import numpy as np
Y = np.array([1, 2, 3, 4])
print("Output of .show method would be: ", Y.shape, " for ", Y)
print("Output of .show[0] method would be: ", Y.shape[0], " for ", Y)
print("Output for i in range(Y.shape[0]): ", end=" ")
for i in range(Y.shape[0]):
print(Y[i], end=" ")输出结果Output of .show method would be: (4,) for [1 2 3 4] Output of .show[0] method would be: 4 for [1 2 3 4] Output for i in range(Y.shape[0]): 1 2 3 4
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短