Use:

np.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.

Answer from Winston Ewert on Stack Overflow
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.5 โ€บ reference โ€บ generated โ€บ numpy.concatenate.html
numpy.concatenate โ€” NumPy v2.5 Manual
In cases where a MaskedArray is expected as input, use the ma.concatenate function from the masked array module instead. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> b = np.array([[5, 6]]) >>> np.concatenate((a, b), axis=0) array([[1, 2], [3, 4], ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_join.asp
NumPy Joining Array
We pass a sequence of arrays that we want to join to the concatenate() function, along with the axis. If axis is not explicitly passed, it is taken as 0. ... import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) arr = np.concatenate((arr1, arr2)) print(arr) Try it Yourself ยป
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ concatenate
NumPy concatenate()
Here, the `concatenate()` function takes a sequence of arrays, `array1`, `array2`, etc., and joins them along the specified `axis`. import numpy as np array1 = np.array([1, 2, 3]) array2 = np.array([4, 5, 6]) result = np.concatenate((array1, array2)) print(result) # Output: [1, 2, 3, 4, 5, ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ numpy โ€บ numpy_concatenate.htm
Numpy Concatenate() Function
The Numpy Concatenate() Function is used to join a sequence of arrays along an existing axis. This function takes a tuple or list of arrays to concatenate and an optional axis parameter that specifies the axis along which the arrays will be joined.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.concatenate.html
numpy.concatenate โ€” NumPy v2.6.dev0 Manual
In cases where a MaskedArray is expected as input, use the ma.concatenate function from the masked array module instead. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> b = np.array([[5, 6]]) >>> np.concatenate((a, b), axis=0) array([[1, 2], [3, 4], [5, 6]]) >>> np.concatenate((a, b.T), axis=1) array([[1, 2, 5], [3, 4, 6]]) >>> np.concatenate((a, b), axis=None) array([1, 2, 3, 4, 5, 6])
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ numpy-concatenate
How to Use np.concatenate() in NumPy (With Examples and Comparisons) | Codecademy
This function returns a new array that contains the concatenation of the given arrays. Next, letโ€™s see an example that uses the np.concatenate() function to join two NumPy arrays vertically (axis=0):
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ machine learning โ€บ numpy-concatenate-function-python
numpy.concatenate() function in Python - GeeksforGeeks
July 12, 2025 - Python ยท import numpy as np arr1 ... print("Result:", result) Output : Result: [1 2 3 4 5 6] For 2D arrays you can concatenate along rows (default behavior) or columns ยท...
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ concatenate
NumPy concatenate()
The NumPy concatenate() method joins a sequence of arrays along an existing axis. The NumPy concatenate() method joins a sequence of arrays along an existing axis.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
NumPy: Concatenate arrays with np.concatenate, np.stack, etc. | note.nkmk.me
February 4, 2024 - For 2D arrays, axis=0 concatenates vertically, and axis=1 concatenates horizontally. a1 = np.ones((2, 3), int) print(a1) # [[1 1 1] # [1 1 1]] a2 = np.full((2, 3), 2) print(a2) # [[2 2 2] # [2 2 2]] print(np.concatenate([a1, a2], 0)) # [[1 1 1] # [1 1 1] # [2 2 2] # [2 2 2]] print(np.concatenate([a1, a2], 1)) # [[1 1 1 2 2 2] # [1 1 1 2 2 2]]
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.0 โ€บ reference โ€บ generated โ€บ numpy.concatenate.html
numpy.concatenate โ€” NumPy v2.0 Manual
In cases where a MaskedArray is expected as input, use the ma.concatenate function from the masked array module instead. ... >>> a = np.array([[1, 2], [3, 4]]) >>> b = np.array([[5, 6]]) >>> np.concatenate((a, b), axis=0) array([[1, 2], [3, 4], [5, 6]]) >>> np.concatenate((a, b.T), axis=1) ...
๐ŸŒ
w3resource
w3resource.com โ€บ numpy โ€บ manipulation โ€บ concatenate.php
NumPy: numpy.concatenate() function - w3resource
The np.concatenate() function is called with the input arrays x and y.T (transpose of y) and the axis parameter is set to 1 to concatenate along the columns.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ numpy-concatenate-efficient-array-manipulation-in-python
NumPy Concatenate(): Efficient Array Manipulation in Python - StrataScratch
February 1, 2024 - To do that, first we will turn our datasets for each years into values, to be able to concatenate them by using numpy afterwards. And at the end, we will turn the arrays to the pandas datafame, and add column names to see at the end our data, in dataframe format. Here is the code. data_2017_europe_np = data_2017_europe.values data_2018_europe_np = data_2018_europe.values data_2019_europe_np = data_2019_europe.values # Concatenate the arrays along axis 0 (rows) european_data_concatenated_np = np.concatenate([data_2017_europe_np, data_2018_europe_np, data_2019_europe_np], axis=0) # If you need to convert it back to a DataFrame: european_data_concatenated_df = pd.DataFrame(european_data_concatenated_np, columns=['Country or region', 'Year', 'Score', 'GDP per capita', 'Healthy life expectancy'])
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 1.25 โ€บ reference โ€บ generated โ€บ numpy.concatenate.html
numpy.concatenate โ€” NumPy v1.25 Manual
In cases where a MaskedArray is expected as input, use the ma.concatenate function from the masked array module instead. ... >>> a = np.array([[1, 2], [3, 4]]) >>> b = np.array([[5, 6]]) >>> np.concatenate((a, b), axis=0) array([[1, 2], [3, 4], [5, 6]]) >>> np.concatenate((a, b.T), axis=1) array([[1, 2, 5], [3, 4, 6]]) >>> np.concatenate((a, b), axis=None) array([1, 2, 3, 4, 5, 6])
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-numpy-concatenate
NumPy Concatenate Vs Append - Python Guides
May 6, 2025 - NumPy allows easy combination of 1D arrays using the concatenate() function. import numpy as np # Create two 1D arrays states_west = np.array(['California', 'Oregon', 'Washington']) states_east = np.array(['New York', 'Massachusetts', 'Florida']) ...
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python:numpy โ€บ built-in functions โ€บ .concatenate()
Python:NumPy | Built-in Functions | .concatenate() | Codecademy
May 1, 2025 - To append one NumPy array to another, use the .concatenate() function with the arrays in a sequence: ... np.concatenate() joins arrays along an existing axis, while np.stack() adds a new axis (e.g., stacking rows into a 2D array).
๐ŸŒ
Squash
squash.io โ€บ working-with-numpy-concatenate
Working with Numpy Concatenate - Squash Labs
March 28, 2024 - For example, let's say we have two arrays: array1 with shape (3,) and array2 with shape (2, 3). When we try to concatenate these arrays, Numpy will automatically reshape array1 to have shape (1, 3) so that it matches the shape of array2. ... import numpy as np array1 = np.array([1, 2, 3]) array2 = np.array([[4, 5, 6], [7, 8, 9]]) result = np.concatenate((array1, array2)) print(result)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ joining-numpy-array
Joining NumPy Array - GeeksforGeeks
July 15, 2025 - numpy.concatenate() joins two or more arrays along an existing axis without adding new dimensions. It is fast and efficient for straightforward array joining. ... import numpy as np a = np.array([1, 2]) b = np.array([3, 4]) res = np.concatenate((a, ...
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ 4f4826d5-e2f8-4ffd-9fd0-6f513353d70a โ€บ a4da9564-36a0-4109-b920-88fc7b89ddbb โ€บ 01c5aec4-0b6c-44fa-90b2-fc36fee4898a
Learn Array Concatenation | Commonly used NumPy Functions
Concatenating 2D arrays is performed in a similar way, but you also have to specify the axis parameter: 123456789 import numpy as np array1 = np.array([[1, 2], [3, 4]]) array2 = np.array([[5, 6], [7, 8]]) # Concatenating along the axis 0 (rows) concatenated_array_rows = np.concatenate((array1, array2)) print(f'Axis = 0:\n{concatenated_array_rows}') # Concatenating along the axis 1 (columns) concatenated_array_columns = np.concatenate((array1, array2), axis=1) print(f'Axis = 1:\n{concatenated_array_columns}') Run Code ยท