Issue
I tried Concatenating 2 numpy arrays but I got an error. The error is:
Traceback (most recent call last):
File "C:\Users\hp\Desktop\Python\Numpy\OperationsOnArrays1.py", line 28, in <module>
array3 = np.concatenate((array,array2))
File "<__array_function__ internals>", line 5, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 3 and the array at index 1 has size 2
import numpy as np
array = np.array([2,43,2,
4,1,3])
# Sorting an array by ascending order
array = np.sort(array)
# Sorting by specifying the axis
array = np.array([[2,5,4],[3,2,1]])
# array5 = np.array([[2,5,4],[3,2,1]])
array = np.sort(array,axis=1)
# Concate (adding 1 array after another)
array2 = np.zeros((4,2))
print(array2)
array3 = np.concatenate((array,array2))
print(array)
print(array2)
print(array3)
Solution
print(array.shape, array2.shape)
will print (2, 3) (4, 2)
.
For concatenate to work, the first dimension has to be the same in all arrays.
Answered By - Gulzar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.