Reputation: 326
I have a list of tuples, and I want to concatenate them to values stored in a numpy array. Is it possible?
I've tried to use the zip function, because I want a resultant tuple like:
(original_tuple_value,numpy_array_value)
For clarification, a possible input is: import numpy as np
tupla_data = [tuple(["String 1"]), tuple(["String 2"]), tuple(["String3"])]
array_data = np.array([0,1,2])
A print version would be:
Example of list of tuples: [('String 1',), ('String 2',), ('String3',)]
Example of numpy array: [0 1 2]
Desired final output tuples: [('String 1', 0), ('String 2', 1), ('String3', 2)]
Upvotes: 2
Views: 1098
Reputation: 221624
If I understood it correctly, like this -
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')]
Upvotes: 1