Sep-21-2021, 03:33 PM
Hi,
I am trying to add columns to a numpy array but i am getting an error
I am trying to add columns to a numpy array but i am getting an error
import numpy as np numbers = np.array([ [2,4], [8,10], [50,100] ]) add = numbers[:,0] + numbers[:,1] mul = numbers[:,0] * numbers[:,1] numbers = np.hstack((numbers,add)) numbers = np.hstack((numbers,mul))i am getting this error:
Error:Traceback (most recent call last):
File "main.py", line 11, in <module>
numbers = np.hstack((numbers,add))
File "<__array_function__ internals>", line 5, in hstack
File "/usr/lib/python3.8/site-packages/numpy/core/shape_base.py", line 346, in hstack
return _nx.concatenate(arrs, 1)
File "<__array_function__ internals>", line 5, in concatenate
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)
** Process exited - Return Code: 1 **
Press Enter to exit terminal