Reputation: 71
Here is my matrices and codeline:
d = np.array([[1,2,3],[6,7,8],[11,12,13],
[16,17,18]])
e = np.array([[ 4, 5],[ 9, 10],[14, 15],[19, 20]])
np.concatenate(d,e)
and this is the error that I get:
TypeError: only integer scalar arrays can be converted to a scalar index
Upvotes: 0
Views: 34
Reputation: 4472
Since those arrays have different dimensions you should specify the axis concatenate you what like the follow:
1) np.concatenate((d,e), axis=1)
array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]])
or
2)np.concatenate((d,e), axis=None)
array([ 1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 4, 5, 9, 10, 14,
15, 19, 20])
Upvotes: 0
Reputation: 181
You have a syntax mistake in np.concatenate(d,e)
, the syntax requires d
and e
to be in a tuple, like: np.concatenate((d,e))
. I tested it, and axis=1
is also required for it to work.
np.concatenate((d, e), axis=1)
is the solution
Upvotes: 1