There is a np.array:
[
array(['x_0', '2/20/1990', '3/20/1990'], dtype=object),
array(['x_1', '1', '2'], dtype=object),
array(['x_3', 'foo', 'bar'], dtype=object), etc...]
I want to make an array that will contain all of this values grouped (all first values with 1-st values, second values with second, and separated with "\n":
like this:
[array(['x_0\nx_1\nx_n, '2/20/1990\n1\nfoo', '3/20/1990\n2\bar', etc], dtype=object)]
You can use python built-in zip function and join :
>>> a=[
... np.array(['x_0', '2/20/1990', '3/20/1990'], dtype=object),
... np.array(['x_1', '1', '2'], dtype=object),
... np.array(['x_3', 'foo', 'bar'], dtype=object)]
>>> new=np.array(['\n'.join(k) for k in zip(*a)],dtype=object)
>>> new
array(['x_0\nx_1\nx_3', '2/20/1990\n1\nfoo', '3/20/1990\n2\nbar'], dtype=object)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With