I have an ndarray that looks like this:
In [1]: a
Out [1]: array(['x','y'], dtype=object)
Now I wanted to append a "z" to the end of it:
In [2]: print([a,'z'])
[array(['x','y'],dtype=object), 'z']
Instead, what I want is:
['x','y','z']
Any idea?
You can do it using numpy.append:
import numpy as np
a = np.array(['x','y'])
b = np.append(a,['z'])
In [8]:b
Out[8]: array(['x', 'y', 'z'], dtype='<U1')
You can use numpy.append:
import numpy as np
a = np.array(['x', 'y'])
np.append(a, 'z')
# array(['x', 'y', 'z'],
# dtype='<U1')
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