import numpy as np
list = [[1,3,5,7],[2,4,6,8]]
np_list = np.array(list) #将l列表数据转化为数组类型
print(np_list)
'''
[[1 3 5 7]
[2 4 6 8]]
'''
np_list1 = np.array(list,dtype=np.float) # 通过dtype定义数组的类型,默认的自动识别
print(np_list1) #bool,int,int8,int32,int16,int64,int128,uint8等,float。float16/32/等
'''
[[ 1. 3. 5. 7.]
[ 2. 4. 6. 8.]]
'''
#数据的属性
print(np_list.shape) # (2, 4) 两行四列
print(np_list.ndim) # 2 数据的维度
print(np_list.dtype) # int32 数组的类型
print(np_list.itemsize) # 4 每个数据的大小
print(np_list.size) # 8 数据的个数
# 一些数组 some arrays
print(np.ones((3,5)))
'''
[[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
'''
print(np.zeros((2,4)))
'''
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]]
'''
# 随机数
# rand
print(np.random.rand(2,4)) #生成一个两行四类的随机数
'''
[[ 0.72024033 0.93403506 0.73121086 0.84075394]
[ 0.98034306 0.6471637 0.77923702 0.44984363]]
'''
print(np.random.rand()) # 0.702153504735015 一个随机数
# randint
print(np.random.randint(1,10)) # 必须要填入数字范围
print(np.random.randint(1,10,3)) # 前面两个数字是范围,后面的一是输出的随机数个数
# randn 标准动态生成的随机数
print(np.random.randn()) # 0.2021606168747088
print(np.random.randn(2,4)) # 两行四列的正态随机数
'''
[[-0.43522053 0.288716 1.5751424 -0.89094638]
[-1.12602864 1.27198812 -0.4784293 1.90768013]]
'''
# choice 随机生成 制定数组内的 随机数
print(np.random.choice([10,20,30])) # 随机生成一个随机数
print(np.random.choice([10,20,30],2)) # 随机生成制定个随机数
# 数学函数的分布
print(np.random.beta(1,10,100)) # beta函数的分布