๐ŸŒ
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]]) ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, 6) array([1, 2, 3, 4, 5, 6]) >>> np.reshape(a, 6, order='F') array([1, 4, 2, 5, 3, 6])
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_reshape.asp
NumPy Array Reshaping
By reshaping we can add or remove dimensions or change number of elements in each dimension. Convert the following 1-D array with 12 elements into a 2-D array. The outermost dimension will have 4 arrays, each with 3 elements: import numpy as ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.0 โ€บ reference โ€บ generated โ€บ numpy.ndarray.reshape.html
numpy.ndarray.reshape โ€” NumPy v2.0 Manual
Unlike the free function numpy.reshape, this method on ndarray allows the elements of the shape parameter to be passed in as separate arguments.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-reshape-python
numpy.reshape() in Python - GeeksforGeeks
June 26, 2026 - Explanation: np.reshape(a, (4, 2)) rearranges the 8 elements into a matrix with 4 rows and 2 columns. Example 2: Sometimes the exact size of one dimension is not known in advance. In such cases, -1 can be used and NumPy automatically calculates the missing dimension.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Learn to reshape NumPy arrays in 4 minutes! โ†”๏ธ - YouTube
#python #coding #numpy # reshape() = Changes the shape of an array# w/o altering its underlying data# array.reshape...
Published: November 9, 2025
๐ŸŒ
Medium
medium.com โ€บ @jennycoreholt โ€บ numpy-reshape-explained-turning-data-into-the-shape-you-need-5406b93653fc
NumPy reshape() Explained: Turning Data Into the Shape You Need | by Jenny Core-Holt | Medium
June 29, 2025 - NumPy reshape() Explained: Turning Data Into the Shape You Need What is np.reshape()? np.reshape() is a method in NumPy that changes the shape (or structure) of an array without changing the data โ€ฆ
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.3 โ€บ reference โ€บ generated โ€บ numpy.reshape.html
numpy.reshape โ€” NumPy v2.3 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]]) ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, 6) array([1, 2, 3, 4, 5, 6]) >>> np.reshape(a, 6, order='F') array([1, 4, 2, 5, 3, 6])
๐ŸŒ
Medium
medium.com โ€บ data-science โ€บ get-into-shape-14637fe1cd32
Shaping and reshaping NumPy and pandas objects to ...
April 16, 2021 - AttributeError: 'Series' object has no attribute 'reshape' We could change our Series into a NumPy array and then reshape it to have two dimensions. However, as you saw above, thereโ€™s an easier way to make x a 2D object.
Find elsewhere
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ understanding-the-differences-between-numpy-reshape1-1-and-reshape1-1
Understanding the Differences Between Numpy Reshape(-1, 1) and Reshape(1, -1) | Saturn Cloud Blog
May 1, 2026 - Numpy is a powerful library in ... of the most commonly used functions in Numpy is reshape(), which gives a new shape to an array without changing its data....
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ reshape
NumPy reshape()
arr = np.arange(24) # Reshape 1D array of 24 elements to 3D array with dimensions 2x3x4 reshaped_arr = np.reshape(arr, (2, 3, 4)) Ensure compatibility. The new shape must have the same total number of elements as the original array. A mismatch will result in a `ValueError`. Use `-1` wisely. Let NumPy infer one of the dimensions by setting it to `-1`, simplifying the code.
๐ŸŒ
Real Python
realpython.com โ€บ numpy-reshape
Using NumPy reshape() to Change the Shape of an Array โ€“ Real Python
July 20, 2026 - In the following sections, youโ€™ll work through several short examples that use reshape() to convert arrays from one shape into another. NumPyโ€™s reshape() enables you to change the shape of an array into another compatible shape.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.reshape.html
numpy.reshape โ€” NumPy v2.5 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]]) ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, 6) array([1, 2, 3, 4, 5, 6]) >>> np.reshape(a, 6, order='F') array([1, 4, 2, 5, 3, 6])
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.reshape.html
numpy.reshape โ€” NumPy v2.6.dev0 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]]) ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, 6) array([1, 2, 3, 4, 5, 6]) >>> np.reshape(a, 6, order='F') array([1, 4, 2, 5, 3, 6])
Top answer
1 of 12
902

The criterion to satisfy for providing the new shape is that 'The new shape should be compatible with the original shape'

numpy allow us to give one of new shape parameter as -1 (eg: (2,-1) or (-1,3) but not (-1, -1)). It simply means that it is an unknown dimension and we want numpy to figure it out. And numpy will figure this by looking at the 'length of the array and remaining dimensions' and making sure it satisfies the above mentioned criteria

Now see the example.

z = np.array([[1, 2, 3, 4],
         [5, 6, 7, 8],
         [9, 10, 11, 12]])
z.shape
(3, 4)

Now trying to reshape with (-1) . Result new shape is (12,) and is compatible with original shape (3,4)

z.reshape(-1)
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12])

Now trying to reshape with (-1, 1) . We have provided column as 1 but rows as unknown . So we get result new shape as (12, 1).again compatible with original shape(3,4)

z.reshape(-1,1)
array([[ 1],
   [ 2],
   [ 3],
   [ 4],
   [ 5],
   [ 6],
   [ 7],
   [ 8],
   [ 9],
   [10],
   [11],
   [12]])

The above is consistent with numpy advice/error message, to use reshape(-1,1) for a single feature; i.e. single column

Reshape your data using array.reshape(-1, 1) if your data has a single feature

New shape as (-1, 2). row unknown, column 2. we get result new shape as (6, 2)

z.reshape(-1, 2)
array([[ 1,  2],
   [ 3,  4],
   [ 5,  6],
   [ 7,  8],
   [ 9, 10],
   [11, 12]])

Now trying to keep column as unknown. New shape as (1,-1). i.e, row is 1, column unknown. we get result new shape as (1, 12)

z.reshape(1,-1)
array([[ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12]])

The above is consistent with numpy advice/error message, to use reshape(1,-1) for a single sample; i.e. single row

Reshape your data using array.reshape(1, -1) if it contains a single sample

New shape (2, -1). Row 2, column unknown. we get result new shape as (2,6)

z.reshape(2, -1)
array([[ 1,  2,  3,  4,  5,  6],
   [ 7,  8,  9, 10, 11, 12]])

New shape as (3, -1). Row 3, column unknown. we get result new shape as (3,4)

z.reshape(3, -1)
array([[ 1,  2,  3,  4],
   [ 5,  6,  7,  8],
   [ 9, 10, 11, 12]])

And finally, if we try to provide both dimension as unknown i.e new shape as (-1,-1). It will throw an error

z.reshape(-1, -1)
ValueError: can only specify one unknown dimension
2 of 12
118

Say we have a 3 dimensional array of dimensions 2 x 10 x 10:

r = numpy.random.rand(2, 10, 10) 

Now we want to reshape to 5 X 5 x 8:

numpy.reshape(r, shape=(5, 5, 8)) 

will do the job.

Note that, once you fix first dim = 5 and second dim = 5, you don't need to determine third dimension. To assist your laziness, Numpy gives the option of using -1:

numpy.reshape(r, shape=(5, 5, -1)) 

will give you an array of shape = (5, 5, 8).

Likewise,

numpy.reshape(r, shape=(50, -1)) 

will give you an array of shape = (50, 4)

You can read more at http://anie.me/numpy-reshape-transpose-theano-dimshuffle/

๐ŸŒ
CodingNomads
codingnomads.com โ€บ np-reshape-np-flatten-np-ravel
NumPy Array Manipulation: np.reshape, np.flatten, np.ravel ...
To do that, we use .reshape() ... NumPy Reshape will take the elements of the 1D array and place them into the new specified shape. It will fill the array based on the order of the elements in the original array.
Top answer
1 of 5
26

Reshape doesn't change the data as mentioned here. Resize changes the data as can be seen here.

Here are some examples:

>>> numpy.random.rand(2,3)
array([[ 0.6832785 ,  0.23452056,  0.25131171],
       [ 0.81549186,  0.64789272,  0.48778127]])
>>> ar = numpy.random.rand(2,3)
>>> ar.reshape(1,6)
array([[ 0.43968751,  0.95057451,  0.54744355,  0.33887095,  0.95809916,
         0.88722904]])
>>> ar
array([[ 0.43968751,  0.95057451,  0.54744355],
       [ 0.33887095,  0.95809916,  0.88722904]])

After reshape the array didn't change, but only output a temporary array reshape.

>>> ar.resize(1,6)
>>> ar
array([[ 0.43968751,  0.95057451,  0.54744355,  0.33887095,  0.95809916,
         0.88722904]])

After resize the array changed its shape.

2 of 5
10

One major difference is reshape() does not change your data, but resize() does change it. resize() first accommodates all the values in the original array. After that, if extra space is there (or size of new array is greater than original array), it adds its own values. As @David mentioned in comments, what values resize() adds depends on how that is called.

You can call reshape() and resize() function in the following two ways.

numpy.resize()

ndarray.resize() - where ndarray is an n dimensional array you are resizing.

You can similarly call reshape also as numpy.reshape() and ndarray.reshape(). But here they are almost the same except the syntax.

One point to notice is that, reshape() will always try to return a view wherever possible, otherwise it would return a copy. Also, it can't tell what will be returned when, but you can make your code to raise error whenever the data is copied.

For resize() function, numpy.resize() returns a new copy of the array whereas ndarray.resize() does it in-place. But they don't go to the view thing.

Now coming to the point that what the values of extra elements should be. From the documentation, it says

If the new array is larger than the original array, then the new array is filled with repeated copies of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.

So for ndarray.resize() it is the value 0, but for numpy.resize() it is the values of the array itself (of course, whatever can fit in the new size). The below code snippet will make it clear.

In [40]: arr = np.array([1, 2, 3, 4])

In [41]: np.resize(arr, (2,5))
Out[41]:
array([[1, 2, 3, 4, 1],
      [2, 3, 4, 1, 2]])

In [42]: arr.resize((2,5))

In [43]: arr
Out[43]:
array([[1, 2, 3, 4, 0],
       [0, 0, 0, 0, 0]])

You can also see that ndarray.resize() returns None and does the resizing in-place.

๐ŸŒ
ProjectPro
projectpro.io โ€บ recipes โ€บ reshape-numpy-array-in-python
How to Reshape a NumPy Array using np.reshape? -
February 22, 2024 - Practice more NumPy Operations with ProjectPro! The reshape function in NumPy allows you to give a new shape to an array without changing its data. It returns a new array with the same data but a different shape.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.ndarray.reshape.html
numpy.ndarray.reshape โ€” NumPy v2.5 Manual
Unlike the free function numpy.reshape, this method on ndarray allows the elements of the shape parameter to be passed in as separate arguments.