user19862793
user19862793

Reputation: 171

Appending two arrays in Python

I am trying to append two numpy arrays A and J[0] using np.concatenate but there is an error. I also present the expected output.

import numpy as np

A=np.array([ 1,  3,  5,  7,  9, 10, 12, 13, 14, 15, 16, 18, 20, 21, 22, 23])

J=[[4, 6, 8, 11, 17, 19]]
J=np.array(J)
T=np.concatenate(A,J[0],axis=1)

The error is

in <module>
    T=np.concatenate(A,J[0],axis=1)

  File "<__array_function__ internals>", line 4, in concatenate

TypeError: concatenate() got multiple values for argument 'axis'

The expected output is

array([ 1,  3,  4, 5,  6, 7,  8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23])

Upvotes: 0

Views: 66

Answers (1)

Tom McLean
Tom McLean

Reputation: 6327

T = np.sort(np.concatenate((A, J[0])))

Upvotes: 1

Related Questions