Python中的numpy数组改变维度

通过ravelfalttenshaperesize改变数组维度

import numpy as np
# 生成2,3,4维度的数组
b=np.arange(24).reshape(2,3,4)
print(b)
print("-----------------------------------\n")

# 查看数组维度
print("查看数组维度")
print(b.shape)
print("-----------------------------------\n")

# ravel函数不会更改原数组
# flatten函数会更改原数组
print("平展数组")
print(b.ravel())
c=b.flatten()
print(c)
print(b.flatten())
print("-----------------------------------\n")

# 更改数组维度
print("更改数组维度")
b.shape=[4,6]
print(b)
print("----------------\n")
print(np.resize(b, (2, 12)))
print(b.resize((3,8)))
print(b)
print("-----------------------------------\n")

你可能感兴趣的:(numpy,Python,python,numpy)