Skip to content Skip to sidebar Skip to footer

How To Join Two Arrays In A Tuple Into One Array In Numpy

I have a tuple with two arrays and I want to make it one array: The tuple: (array([['No', 'Yes', 'No', 'No'], ['No', 'Yes', 'No', 'Yes'], ['No', 'No', 'No', 'Yes']],

Solution 1:

Just np.vstack them

np.vstack(tuple_of_array)

example from my terminal:

>>> import numpy as np
>>> array = np.array  # Because I'm lazy and wanted to copy/paste your input ;-)>>> arrays = (array([['No', 'Yes', 'No', 'No'],
...        ['No', 'Yes', 'No', 'Yes'],
...        ['No', 'No', 'No', 'Yes']], dtype='<U7'), 
... array([['Yes', 'No', 'No', 'Yes']], dtype='<U7'))
>>> np.vstack(arrays)
array([[u'No', u'Yes', u'No', u'No'],
       [u'No', u'Yes', u'No', u'Yes'],
       [u'No', u'No', u'No', u'Yes'],
       [u'Yes', u'No', u'No', u'Yes']], 
      dtype='<U7')

Solution 2:

You can also do this:

t = (array([['No', 'Yes', 'No', 'No'],
       ['No', 'Yes', 'No', 'Yes'],
       ['No', 'No', 'No', 'Yes']], dtype='<U7'), 
array([['Yes', 'No', 'No', 'Yes']], dtype='<U7'))

np.append(t[0], t[1], axis=0)

Post a Comment for "How To Join Two Arrays In A Tuple Into One Array In Numpy"