'I want to add a copy of the first column as a new column at the end of the array, can someone explain the difference in dimentions of the error?

b = np.concatenate((a, a[:,0]), axis=1)

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)



Solution 1:[1]

You have to use:

np.c_[a,a[:,0]]

otherwise you should reshape a[:,0] as:

np.concatenate((a,a[:,0].reshape(-1,1)), axis=1)

this because a[:,0] is a 1d array and you will not have a second axis (axis=1). This explains the error "the array at index 1 has 1 dimension(s)"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salvatore Daniele Bianco