Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
reshape() gives a NumPy array a new shape without changing its values. Use arr.reshape(new_shape) or np.reshape(arr, new_shape); the requested dimensions must contain exactly the same number of elements, although one dimension may be -1 so NumPy can infer it. The default traversal is C order, and the result may be a view or a copy depending on the array’s layout and the requested order.
This guide covers shape arithmetic, rows and columns, C/F/A order, inferred dimensions, views versus copies, current NumPy arguments, common errors, and practical patterns.
How do I reshape a NumPy array?
Import NumPy, create or obtain an array, then call its reshape() method:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →import numpy as np
arr = np.arange(6)
reshaped = arr.reshape(3, 2)
print(reshaped)
# [[0 1]
# [2 3]
# [4 5]]
print(reshaped.shape) # (3, 2)
The top-level function is equivalent:
reshaped = np.reshape(arr, (3, 2))
NumPy’s reference describes reshape as giving “a new shape to an array without changing its data.” The original object is not reshaped in place; assign the returned array if you need to keep it.
#1 Best Overall
Current NumPy documentation lists numpy.reshape(a, /, shape=None, order='C', *, newshape=None, copy=None). Use shape in new code. The older newshape keyword has been deprecated since NumPy 2.1, although it remains for compatibility.
How do I reshape an array to rows and columns?
Multiply the requested dimensions and compare that product with arr.size. A six-element array can become 2×3, 3×2, 1×6, or 6×1:
x = np.arange(6)
rows_columns = x.reshape(2, 3)
print(rows_columns)
# [[0 1 2]
# [3 4 5]]
one_row = x.reshape(1, 6)
one_column = x.reshape(6, 1)
The shape tuple is explicit and easy to read, but the method also accepts dimensions as separate positional arguments:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
x.reshape(2, 3) # same as x.reshape((2, 3))
x.reshape(1, 6)
Reshape does not pad, truncate, or reorder values arbitrarily. A request whose dimensions multiply to a different number raises a ValueError:
x.reshape(4, 2) # ValueError: 6 elements cannot fill 8 positions
Check the element count before reshaping
target = (3, 4)
if np.prod(target) != x.size:
raise ValueError("target shape has the wrong number of elements")
arr.size is the total number of elements, while arr.shape reports the size of each axis.
How does NumPy reshape infer -1?
Put -1 in one dimension when you know the other dimensions but want NumPy to calculate the remaining size. For six values, (3, -1) means (3, 2):
Rank #2
x = np.arange(6)
print(x.reshape(3, -1).shape) # (3, 2)
print(x.reshape(2, -1))
# [[0 1 2]
# [3 4 5]]
For 30 values, (2, -1, 3) infers 5 because 2 × 5 × 3 = 30:
cube = np.arange(30).reshape(2, -1, 3)
print(cube.shape) # (2, 5, 3)
Only one dimension may be -1; NumPy cannot infer two unknown dimensions. The known dimensions still must divide the element count exactly.
What does order='C' mean in NumPy reshape?
order specifies how NumPy reads values from the input and places them in the output. The default, 'C', uses row-style indexing: the last index changes fastest.
x = np.array([[0, 1],
[2, 3],
[4, 5]])
print(np.reshape(x, (2, 3)))
# [[0 1 2]
# [3 4 5]]
In this example, the values are traversed as 0, 1, 2, 3, 4, 5 and then placed into two rows of three.
What does order='F' mean?
'F' uses column-style indexing: the first index changes fastest during traversal. It is useful when matching a Fortran-style indexing convention or a data source documented that way.
print(np.reshape(x, (2, 3), order='F'))
# [[0 4 3]
# [2 1 5]]
Do not interpret order='F' as a guarantee that the result’s physical memory layout is Fortran-contiguous. C and F describe indexing order for the reshape operation; the returned array’s contiguity is not guaranteed.
When should you use order='A'?
'A' uses Fortran indexing if the input is Fortran-contiguous and C indexing otherwise. It can preserve the input’s existing convention when code handles arrays from multiple sources. If you simply need ordinary Python/NumPy row traversal, leave the default 'C'.
Does NumPy reshape return a view or a copy?
It can return either. NumPy creates a view when the existing strides and requested order allow the new shape without moving data; otherwise it allocates a copy. Therefore, never assume reshape is always zero-copy or that the result always owns independent storage.
a = np.arange(6)
b = a.reshape(2, 3)
b[0, 0] = 99
print(a) # often shows 99 because this reshape can be a view
The example demonstrates possible sharing, not a universal promise for every array. Sliced, transposed, or otherwise non-contiguous inputs can require a copy.
Recommended Free Tools
Control copying with copy
With the current function signature, copy=None copies only when required by the requested order, copy=True always permits and requests a copy, and copy=False raises ValueError if a copy cannot be avoided.
a = np.arange(6)
view_or_copy = np.reshape(a, (2, 3), copy=None)
independent = np.reshape(a, (2, 3), copy=True)
# strict_view raises ValueError if this particular operation needs copying
strict_view = np.reshape(a, (2, 3), copy=False)
For an actual array, inspect sharing rather than inferring it from the call:
np.shares_memory(a, view_or_copy)
Reshape versus transpose, resize, and ravel
- reshape: returns an array with a different shape while preserving the traversal of values selected by
order. - transpose or
.T: permutes axes. It changes which axis is first, second, and so on; it is not a substitute for reshaping. - ravel: flattens an array to one dimension when possible. You can then reshape that one-dimensional traversal.
- ndarray.resize: changes shape and size in place, potentially repeating or truncating data. It is a different operation from reshape.
matrix = np.arange(6).reshape(2, 3)
print(matrix.T.shape) # (3, 2)
print(matrix.reshape(3, 2).shape) # (3, 2), but values are grouped differently
print(matrix.ravel().shape) # (6,)
Practical reshape patterns
Convert a flat batch into rows
records = np.arange(20)
rows = records.reshape(-1, 4)
print(rows.shape) # (5, 4)
This is useful when each record has four fields and the total length is divisible by four.
Add or remove a singleton axis
values = np.arange(4)
column = values.reshape(-1, 1) # (4, 1)
row = values.reshape(1, -1) # (1, 4)
These forms are common when broadcasting requires an explicit row or column dimension.
Reshape multidimensional data
image = np.arange(24).reshape(2, 3, 4)
flat = image.reshape(-1)
restored = flat.reshape(2, 3, 4)
assert np.array_equal(image, restored)
Troubleshooting reshape errors
“cannot reshape array of size … into shape …”
The target product does not equal arr.size. Print both and correct the dimensions, or use one -1 for the unknown dimension.
“can only specify one unknown dimension”
You supplied more than one -1. Calculate all but one dimension yourself.
Unexpected value arrangement
You may need a different traversal order, or you may actually want transpose. Compare a small known array under C and F order before processing production data.
Changes unexpectedly affect the source
The result may share memory with the input. Use copy=True when independent storage is required, and verify with np.shares_memory().
Reshape is slower than expected
A copy may be necessary for a non-contiguous input or requested order. Avoid unnecessary transposes and copies, and choose copy=False when enforcing a no-copy requirement is more important than accepting an exception.
Best Value
Performance, reliability, and API choices
Reshape itself is usually inexpensive when a view is possible, but copying can scale with the number of elements. For large arrays, check contiguity and memory sharing before placing reshape inside a hot loop. Keep shape calculations explicit at data boundaries, validate divisibility, and document whether C or F traversal matches the producer’s format.
The method form reads naturally when you already have an array: arr.reshape(...). The function form is convenient in generic code that receives an array-like object: np.reshape(arr, ...). Both express the same operation. Prefer the modern shape argument over deprecated newshape.
Or skip the browser setup
If your workflow also needs webpage images for documentation, test fixtures, or model context, ScreenshotNeo provides a single screenshot API request instead of configuring a headless browser. It removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with the result identified by response headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use the API documentation at screenshotneo.com/docs/ for all options. A one-call cURL example is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.
Further reading
- NumPy reshape API reference — signature, orders, copying, inference, and deprecation details.
- NumPy: the absolute basics for beginners — introductory shape examples.
- NumPy quickstart — shape manipulation and view/copy distinctions.
Frequently Asked Questions
Can reshape change an array’s data type?
No. Reshape changes the dimensions and indexing of the array; use an explicit dtype conversion such as astype() when you need a different data type.
Can I reshape an empty array?
Yes, but the target shape must still be compatible with zero elements. A dimension inferred with -1 must be mathematically determinable from the remaining dimensions.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Is reshape() available on Python lists?
Python lists do not have this method. Convert first with np.asarray(your_list) or np.array(your_list).
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

