python shape reshape简单用法

python shape reshape简单用法

  1. shape
import numpy as np
# shape
a = np.array([[1,2,3,4,5,6,7,8]])
print(a)
b = a.shape[0]  # 查看行
print(b)
c = a.shape[1]	# 查看列
print(c)

result:
在这里插入图片描述

2.reshape

a = np.array([1,2,3,4,5,6,7,8])
c = a.reshape((4,2))  # 4行2列
d = a.reshape((8,1))  # 8行1列
print(a)
print(c)
print(d)

result:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/kris_paul/article/details/109593410
今日推荐