Python 将元组与numpy数组上的值连接起来
我有一个元组列表,我想将它们连接到numpy数组中存储的值。可能吗 我尝试使用zip函数,因为我想要一个结果元组,如:Python 将元组与numpy数组上的值连接起来,python,numpy,Python,Numpy,我有一个元组列表,我想将它们连接到numpy数组中存储的值。可能吗 我尝试使用zip函数,因为我想要一个结果元组,如: (original_tuple_value,numpy_array_value) 为了澄清,可能的输入是: 将numpy作为np导入 tupla_data = [tuple(["String 1"]), tuple(["String 2"]), tuple(["String3"])] array_data = np.array([0,1,2]) 印刷版将是: 元组列表示例:
(original_tuple_value,numpy_array_value)
为了澄清,可能的输入是:
将numpy作为np导入
tupla_data = [tuple(["String 1"]), tuple(["String 2"]), tuple(["String3"])]
array_data = np.array([0,1,2])
印刷版将是:
元组列表示例:[('string1',),('string2',),('String3',)]
numpy数组的示例:[0 1 2]
所需的最终输出元组:[('string1',0),('string2',1),('String3',2)]如果我理解正确,如下所示-
In [69]: original_tuple_value = [('hello'),('all'),('long')]
In [70]: numpy_array_value = np.array([3,8,2])
In [71]: map(tuple,np.column_stack((original_tuple_value,numpy_array_value)))
Out[71]: [('hello', '3'), ('all', '8'), ('long', '2')]
我收到一条消息说np.array是不可写的。它更像是这样:数组([0,1,2])和元组[(hello),(all),(long)]生成类似[(hello,0),(all,1),(long,2)]的东西,因此,将元组列表连接到numpy数组的值。@RicardoBarrosLourenço
元组[(hello),(all),(long)]
没有意义。它是字符串元组还是数值元组?你能发布最小的可运行的示例输入案例吗?是的,一个字符串元组。它是为nltk naive bayes模块生成训练集的数据转换。