2017-04-13 58 views
0

,我有以下數據:創建多個向量元組的列表和常數

m = 12 
d = 10 
ar1 = np.array([1,4,5,6]) 
type = [p,q,r,s] #same size as ar1 

我想創建的元組下面的列表:

[(12,10,1,p), (12,10,4,q), (12,10,5,r), (12,10,6,s)] 

我試着用zip各種形式,但我無法獲得正確的語法

回答

2

使用zip和列表理解:

[(m,d,x,y) for x,y in zip(ar1,type)] 
1

這應該做的伎倆:

the_tuple = [ (m, d, n[0], n[1]) for n in zip(ar1,type) ]