# All the input array dimensions except for the concatenation axis must match exactly

1 vote
185 views

## Problem :

How to concatenate following numpy arrays?

First np.array with the shape (5,4) as below :

`[[  7487    500 389580      0]`
` [  7488    501 392994      0]`
` [  7491    508 389247      0]`
` [  7491    508 389247      0]`
` [  7492    502 399013      0]]`

Second np.array with the shape (1,5) as below :

`[  16.   15.   12.  12.  17. ]`

The Final result must be as shown below :

`[[  7487    500    389580    0   16]`
` [  7488    501    392994    0   15]`
` [  7491    508    389247    0   12]`
` [  7491    508    389247    0   12]`
` [  7492    502    399013    0   17]]`

I have already tried np.concatenate([array1, array2]) but i get below error

ValueError: all the input arrays must have same number of dimensions

How can I get the required output?

## Solution :

You can follow the approach as given below :

`import numpy as mynp`
`x = mynp.random.randint(100, size=(5, 4))`
`y = [16, 15, 12, 12, 17]`
`print(x)`
`val = mynp.concatenate((x,mynp.reshape(y,(x.shape[0],1))),axis=1)`
`print(val)`

The output will be as below:

`[[32 37 35 53]`
` [64 23 95 76]`
` [17 76 11 30]`
` [35 42  6 80]`
` [61 88  7 56]]`
`[[32 37 35 53 16]`
` [64 23 95 76 15]`
` [17 76 11 30 12]`
` [35 42  6 80 12]`
` [61 88  7 56 17]]`

## Related questions

1 vote
2 answers 295 views
295 views
Problem : I am beginner to numpy. I am trying to execute my code but I am facing below error. &ldquo;Valueerror: all the input arrays must have same number of dimensions&rdquo;. I want to have my all the arrays with a same shape. I am trying to fix above error from past couple of days but still unable to fix it. I am looking for some help in fixing above error.
1 answer 20 views
20 views
2 answers 1.6K views
1.6K views
Problem : I got following rather cryptic error message: the truth value of an array with more than one element is ambiguous. use a.any() or a.all()
1 answer 2 views
2 views
Problem: I know there is a ton of these threads but all of them are for very simple cases like 3x3 matrices and things of that sort and the solutions do not even begin to apply to my situation. So I'm trying to graph G versus l1 (that's not an eleven, but an ... 250 data points. I had another user (shout out to Hugh Bothwell!) help me with an error in my code, but now another error has surfaced.
1 vote
2 answers 295 views
295 views
Problem: Hello guys, Well, I am working with a NumPy array after learning the array a little bit. I am trying to print a particular element from each row from a two-dimensional array. While I am trying to run the program it returns an error Indexerror: too many indices for ... ;s wrong with this and how may I get rid of this? I am looking forward to hearing back from you guys. Thanks a lot.
1 answer 8 views
8 views
Problem: I am really confused as to why this error appears. Here is my code: import numpy as np x = np.array([0, 0]) y = np.array([10, 10]) a = np.array([1, 6]) b = np.array([3, 7]) points = [x, y, a, b] max_pair = [x, y] other_pairs = ... 5, 6] not in max_pair) >>>False Why does this happen when using NumPy arrays? not in/inis ambiguous for existence? What is the correct syntax using any()\all()?
1 answer 1.8K views
1.8K views
Problem : Currently I am trying to learn NumPy. I am trying to execute my code but I am facing following error while trying to use my code. TypeError: Cannot cast array data from dtype('float64')            to dtype('S32') according to the rule 'safe' Please Note : My NumPy version is 1.11.0. How can I fix the above error ?