import numpy as np
list =[1,2,3,4]
oneArray=np.array(list)
print(list)
print(oneArray)
import numpy as np
import random
t1=np.array([1,2,3])
print(t1)#[1 2 3]
print(type(t1))#<class 'numpy.ndarray'>数组类型
t2=np.array(range(10))
print(t2)#[0 1 2 3 4 5 6 7 8 9]
print(type(t2))#<class 'numpy.ndarray'>
t3=np.arange(2,10,2)
print(t3)#[2 4 6 8]
print(type(t3))#<class 'numpy.ndarray'>
print(t3.dtype)#int32
t4=np.array(range(1,4),dtype="i2")#2个字节16位
print(t4)#[1 2 3]
print(t4.dtype)#int16
t5=np.array([1,1,0,1,0,1,0],dtype=bool)
print(t5)#[ True True False True False True False]
print(t5.dtype)#bool
t6=t5.astype("int8")
print(t6)#[1 1 0 1 0 1 0]
print(t6.dtype)#int8
t7=np.array([random.random() for i in range(10)])#默认random.random()为0~1小数
print(t7)#[0.32123244 0.74099132 0.89527163 0.82204031 0.65102081 0.38178552 0.50962158 0.34564249 0.63039987 0.39896338]
print(t7.dtype)#float64
t8=np.round(t7,3)#取三位小数
print(t8)#[0.496 0.981 0.203 0.725 0.056 0.179 0.548 0.934 0.875 0.813]