import numpy as np
a = np.array([1,2,3])
b = np.array([4,5,6])
print(“a:”,a)
print(“b:”,b)
tup=(a,b)
vstack = np.vstack(tup)
hstack = np.hstack(tup)
print(“vstack(a,b):\n”,np.vstack( tup ) ,type(vstack) )
print(“hstack(a,b):\n”,np.hstack( tup ) ,type(hstack) )
2D array的水平/垂直堆疊:
import numpy as np
alst2D=[
[1,2,3],
[3,2,1]
]
blst2D=[
[4,5,6],
[6,5,4]
]
a = np.array(alst2D)
b = np.array(blst2D)
print(“array a:\n”,a)
print(“array b:\n”,b)
tup=(a,b)
vstack = np.vstack(tup)
hstack = np.hstack(tup)
print(“vstack(a,b):\n”,np.vstack( tup ) ,type(vstack) )
print(“hstack(a,b):\n”,np.hstack( tup ) ,type(hstack) )
輸出結果:
import numpy as np
Delay = np.linspace(1e-6,1e-4,5)
print(“Delay: \n”,Delay)
DelayAry = np.array(Delay)*2.048*10**9
print(“DelayAry:\n”,DelayAry)
Delay_f = np.uint16( np.floor(DelayAry/2**16))
Delay_s = np.uint16( np.mod(DelayAry,2**16) )
print(“Delay_f & Delay_s: \n”,Delay_f)
print(Delay_s)
Delay_vstack = np.vstack( (Delay_f,Delay_s) )
print(“vstack: \n”,Delay_vstack)
Delay_ravel = Delay_vstack.ravel(“F”).tolist()
#.tolist()將array轉為list
print(“ravel(‘F’): \n”,Delay_ravel)
推薦hahow線上學習python: https://igrape.net/30afN
近期留言