# Concatenating two one-dimensional NumPy arrays

###### Posted By: Anonymous

I have two simple one-dimensional arrays in NumPy. I should be able to concatenate them using numpy.concatenate. But I get this error for the code below:

TypeError: only length-1 arrays can be converted to Python scalars

### Code

```
import numpy
a = numpy.array([1, 2, 3])
b = numpy.array([5, 6])
numpy.concatenate(a, b)
```

Why?

## Solution

The line should be:

```
numpy.concatenate([a,b])
```

The arrays you want to concatenate need to be passed in as a sequence, not as separate arguments.

From the NumPy documentation:

`numpy.concatenate((a1, a2, ...), axis=0)`

Join a sequence of arrays together.

It was trying to interpret your `b`

as the axis parameter, which is why it complained it couldn’t convert it into a scalar.

###### Answered By: Anonymous

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.