[英]creating list of tuples from multiple vectors and constants
I have the following data: 我有以下数据:
m = 12
d = 10
ar1 = np.array([1,4,5,6])
type = [p,q,r,s] #same size as ar1
I want to create the following list of tuples: 我想创建以下元组列表:
[(12,10,1,p), (12,10,4,q), (12,10,5,r), (12,10,6,s)]
I tried using zip
in various forms but I am not able to get the syntax right 我尝试以各种形式使用
zip
,但语法不正确
使用zip
和列表理解:
[(m,d,x,y) for x,y in zip(ar1,type)]
这应该可以解决问题:
the_tuple = [ (m, d, n[0], n[1]) for n in zip(ar1,type) ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.