You want to reshape the array.

Use with AIB = np.reshape(A, (-1, 2))

where -1 infers the size of the new dimension from the size of the input array.

Answer from Matt Ball on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-a-1d-array-to-a-2d-numpy-array
Convert a 1D array to a 2D Numpy array - GeeksforGeeks
July 23, 2025 - Another example is that we can use the reshape method without specifying the exact number for one of the dimensions. Just pass -1 as the value and NumPy will calculate the number.
Discussions

python - Numpy reshape 1d to 2d array with 1 column - Stack Overflow
In numpy the dimensions of the resulting array vary at run time. There is often confusion between a 1d array and a 2d array with 1 column. In one case I can iterate over the columns, in the other c... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert a 2D index into a 1D index?
Next time you should just try it yourself. Your math is correct. More on reddit.com
๐ŸŒ r/csharp
9
4
March 4, 2024
What is the benefit/purpose of using Numpy 1D Arrays over Numpy 2D Arrays?
there is quite a lot of emphasis placed on just using 1 dimensional arrays Where exactly do you see that? So is there any benefit in using 1D Arrays over 2D Arrays? No, not at all. All numpy arrays are stored as 1D in the background, because that's the only way a computer can store data. A nD array is just indexing math. More on reddit.com
๐ŸŒ r/learnpython
5
1
February 1, 2022
Is a (1,n) shaped array not 1D?
No, a (1,n) shaped array has two dimensions. array.reshape(1,-1) asks for a two-dimensional array with a dimension of length 1 and a second dimension as long as required to hold the data. try array.reshape(-1) More on reddit.com
๐ŸŒ r/learnpython
5
4
August 7, 2024
๐ŸŒ
Medium
medium.com โ€บ @whyamit404 โ€บ how-to-reshape-1d-to-2d-in-numpy-f861f3cf73e5
How to Reshape 1D to 2D in NumPy? | by whyamit404 | Medium
February 26, 2025 - .flatten() creates a new 1D array, leaving the original 2D array unchanged. Incompatible shapes? NumPy throws an error โ€” always match the total number of elements. reshape() gives you a new view, while resize() changes the array in place.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_reshape.asp
NumPy Array Reshaping
Try converting 1D array with 8 elements to a 2D array with 3 elements in each dimension (will raise an error): import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7, 8]) newarr = arr.reshape(3, 3) print(newarr) Try it Yourself ยป
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ array-reshaping
NumPy Array Reshaping (With Examples)
May 30, 2023 - We use the reshape() function to reshape a 1D array into a 2D array. For example, import numpy as np array1 = np.array([1, 3, 5, 7, 2, 4, 6, 8]) # reshape a 1D array into a 2D array # with 2 rows and 4 columns result = np.reshape(array1, (2, ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Convert 1D Array to 2D Array in Python (numpy.ndarray, list) | note.nkmk.me
May 15, 2023 - import numpy as np a = np.arange(6) print(a) # [0 1 2 3 4 5] print(a.reshape(2, 3)) # [[0 1 2] # [3 4 5]] print(a.reshape(-1, 3)) # [[0 1 2] # [3 4 5]] print(a.reshape(2, -1)) # [[0 1 2] # [3 4 5]] source: numpy_1d_to_2d.py ยท If you specify a shape that does not match the total number of elements in the original array, an error will be raised.
Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ numpy-reshape
Using NumPy reshape() to Change the Shape of an Array โ€“ Real Python
July 20, 2026 - Can you use reshape() to add dimensions to a NumPy array?Show/Hide ยท Yes. The reshaped array doesnโ€™t need the same number of dimensions as the original, so you can turn a 1D array into a 2D or 3D array whenever the element counts match.
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ 107e7c0c-86fb-4892-98d3-b5bfa71c5ebc โ€บ 8f21d88a-9609-4988-9377-13aec72a7327 โ€บ 39ae9f46-f47f-409d-83b1-f7be8c8d46fa
Learn Reshaping Arrays | Section
In NumPy, when you use -1 in the .reshape() method, it automatically calculates the size of that dimension based on the original array's size, while keeping the total number of elements the same. Using .reshape(-1, 1) is particularly useful ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ reshape-average-stock-data
NumPy Reshape 1D to 2D โ€“ Be on the Right Side of Change
In summary, the function call np.reshape(original_array, (x, y)) will create a 2D array with x rows and y columns. import numpy as np # Problem: Reshape this 1D into a 2D array array_1d = np.array([0, 1, 2, 3, 4, 5]) # Solution: np.reshape(array, shape) array_2d = np.reshape(array_1d, (2, 3)) ...
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ pandas_numpy โ€บ pandas_numpy-exercise-22.php
Reshaping a 1D NumPy array into a 2D array
import numpy as np # Create a 1D NumPy array array_1d = np.array([1, 2, 3, 4, 5, 6, 7, 8]) # Reshape into a 2D array with 2 rows and 4 columns array_2d = np.reshape(array_1d, (2, 4)) # Alternatively, you can use the array's reshape method: # ...
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python:numpy โ€บ built-in functions โ€บ .reshape()
Python:NumPy | Built-in Functions | .reshape() | Codecademy
May 26, 2025 - It returns a reshaped array. If possible, it returns a view of the original array; otherwise, it returns a new copy. The following example shows how to convert a 1D array into a 2D array:
๐ŸŒ
GitHub
bic-berkeley.github.io โ€บ psych-214-fall-2016 โ€บ reshape_and_3d.html
Reshaping and three-dimensional arrays โ€” Functional MRI methods
Notice how NumPy used the 1D array elements. It takes each element from the 1D array, and fills the rows first, and then the columns. We can reshape back to one dimension. >>> arr_2d.reshape((6,)) array([0, 1, 2, 3, 4, 5])
๐ŸŒ
H2K Infosys
h2kinfosys.com โ€บ home โ€บ python tutorials โ€บ using the numpy reshape and numpy flatten in python
Using the NumPy Reshape and NumPy Flatten in Python | H2K Infosys Blog
December 17, 2025 - You can specify -1 for one of the dimensions, and NumPy will automatically infer the correct size based on the number of elements. order: This determines how the array is read and reshaped. 'C' reads row-wise (C-style, default), 'F' reads column-wise (Fortran-style). python # Create a 1D array arr = np.array([1, 2, 3, 4, 5, 6]) # Reshape it to 2D (3 rows, 2 columns) reshaped_arr = np.reshape(arr, (3, 2)) print(reshaped_arr)
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ numpy โ€บ reshape-a-1d-array-into-2d-and-print-strides-using-numpy.php
Reshape a 1D array into 2D and print Strides using NumPy
Reshape the array: Use the reshape() method to convert the 1D array into a 2D array of shape (3, 4). Print Strides: Print the strides of the reshaped array using the strides attribute.
๐ŸŒ
ProjectPro
projectpro.io โ€บ recipes โ€บ reshape-numpy-array-in-python
How to Reshape a NumPy Array using np.reshape? -
February 22, 2024 - If you want to reshape this 1D array into a 2D array with 2 rows and 5 columns, you can use the reshape function.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-reshape-an-array-in-numpy
How to reshape an array in Numpy
When reshaping an array, the new shape should be equal in length to the original shape. In other words, the elements required for reshaping must be equal in both shapes. The array.reshape() function reshapes an array in NumPy...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third party โ€บ numpy โ€บ reshape()
Python Numpy reshape() - Change Array Shape | Vultr Docs
November 15, 2024 - Using the reshape() function in NumPy effectively changes the dimensions of arrays without altering the underlying data, facilitating seamless data manipulation for diverse computational tasks.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.4 โ€บ reference โ€บ generated โ€บ numpy.reshape.html
numpy.reshape โ€” NumPy v2.4 Manual
>>> np.reshape(a, (2, 3)) # C-like index ordering array([[0, 1, 2], [3, 4, 5]]) >>> np.reshape(np.ravel(a), (2, 3)) # equivalent to C ravel then C reshape array([[0, 1, 2], [3, 4, 5]]) >>> np.reshape(a, (2, 3), order='F') # Fortran-like index ordering array([[0, 4, 3], [2, 1, 5]]) >>> np.reshape(np.ravel(a, order='F'), (2, 3), order='F') array([[0, 4, 3], [2, 1, 5]])