# ====================================================
# shape: 通过元组的形式返回数组每一个维度的元素个数
# dtype: 返回元组的元素类型
# ndim属性: 给出数组的维度
# size属性: 返回数组元素的总个数
# itemsize属性: 返回数组中的元素在内存中占有的字节数
# nbytes: 数组占用的总字节书
# T属性: 与transpose函数相同
# 如果是一维数组, 则transpose后等于它本身
print("*" * 20, " 我是分割线", "*" * 20)
a = np.arange(12).reshape(2,6)
print(a.shape)
print(a.dtype)
print(a.ndim)
print(a.size)
print(a.itemsize)
print(a.nbytes) # 数组占用的总字节书
print(a.itemsize * a.size) # 数组占用的总字节书
print(a)
print(a.T)
# ====================================================
# Numpy数组转为 python的List
# tolist, astype
print("*" * 20, " 我是分割线", "*" * 20)
a = np.array([1,2,3,4,5,6])
print(a)
print("转为python的list", a.tolist())
# 二维数组
print("*" * 20, " 我是分割线", "*" * 20)
b = a.reshape(2,3)
print(b)
print("转为python的list", b.tolist())
# astype
print("*" * 20, " 我是分割线", "*" * 20)
a = np.array([1,2,3,4,5,'6']) # 因为最后的'6'为字符串, 所以a为字符串的np数组类型
a1 = a.astype(int) # np的数组转为python的list后, 按照参数转为了int. 如果转换后类型不匹配, 则抛出错误
print(a)
print(a1)