攝影或3C

Python: ndarray的水平/垂直堆疊, import numpy as np ; np.vstack(tuple) ; np.hstack(tuple) ; ravel(“F”) #解開(線團等),把二維array轉成一維

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

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡