Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchIn Python, “array” can mean three different things: a built-in list, the standard-library array.array, or NumPy’s ndarray. Use a list for general-purpose sequences, array.array for compact one-dimensional sequences of constrained basic values, and NumPy when you need multidimensional arrays and array-oriented numerical operations.
Which kind of array does Python mean?
The word is not specific enough to identify one Python type. These structures differ in where they come from, what they can hold, and whether they support multidimensional numerical work.
| Structure | Where it comes from | Element types | Multidimensional shape | Best suited to |
|---|---|---|---|---|
list |
Built into Python | Can contain values of different types | No native multidimensional shape; nested lists can represent rows and columns | General-purpose sequences and mixed values |
array.array |
Python standard library | Constrained to a basic value type selected by a type code | One-dimensional | Mutable one-dimensional sequences of basic values when its narrower feature set is enough |
NumPy ndarray |
External package; NumPy is not part of Python’s standard library | Homogeneous: elements use the array’s dtype | Native support for one or more dimensions | Numerical work with array-oriented operations |
NumPy’s documentation distinguishes its ndarray from the standard-library array.array, which handles one-dimensional arrays with fewer features. See the NumPy v2.5 quickstart, the ndarray reference, and Python’s array module documentation.
How do I create an array in Python?
For NumPy examples below, first import the package as np:
#1 Best Overall
import numpy as np
The constructor numpy.array(object, dtype=...) builds an array from an object such as a Python sequence. A flat sequence creates a one-dimensional array; nested sequences can create arrays with more dimensions. The optional dtype argument specifies the element type. See the numpy.array reference and array creation guide.
Make a one-dimensional array from a list
values = np.array([10, 20, 30, 40])
print(values)
print(values.shape) # (4,)
print(values.ndim) # 1
print(values.size) # 4
print(values.dtype) # NumPy's inferred element type
Here, the input is a Python list, but values is a NumPy array. NumPy chooses a dtype based on the input unless you specify one.
Make a two-dimensional array from nested lists
grid = np.array([[1, 2, 3],
[4, 5, 6]])
print(grid.shape) # (2, 3)
print(grid.ndim) # 2
print(grid.size) # 6
print(grid.dtype)
The shape (2, 3) means two entries along the first axis (rows) and three along the second (columns). The general creation guide also demonstrates building arrays from nested sequences with more dimensions.
Rank #2
Use common numeric constructors
NumPy also provides constructors for sequences and arrays initialized with repeated values. For example:
sequence = np.arange(5) # [0, 1, 2, 3, 4]
zeros = np.zeros((2, 3)) # 2 rows by 3 columns of zeros
ones = np.ones((2, 2), dtype=int) # 2 by 2 array of integers
These functions are useful when the values follow a range or an initial pattern rather than coming from an existing list.
What do shape, ndim, size, and dtype tell me?
shapeis a tuple giving the length along each dimension. A two-row, three-column array has shape(2, 3).ndimis the number of axes (dimensions). A flat array has one axis; a matrix-like array has two.sizeis the total number of elements across all dimensions.dtypedescribes the type used for the array’s elements.
These attributes answer different questions: shape describes layout, ndim counts axes, size counts values, and dtype identifies their representation. For the formal definitions, see the NumPy ndarray reference.
How do I access or slice a NumPy array?
NumPy uses familiar bracket notation. For a two-dimensional array, give row and column indices separated by a comma:
grid = np.array([[1, 2, 3],
[4, 5, 6]])
print(grid[1, 2]) # 6: row index 1, column index 2
print(grid[0]) # first row
Indices start at zero, so grid[1, 2] selects the second row’s third element. A slice selects a range or part of an array:
first_row = grid[0, :]
second_column = grid[:, 1]
print(second_column) # [2, 5]
Important: a slice may share the original data
NumPy slices can be views rather than independent copies. Changing a value through a view can therefore change the source array:
grid = np.array([[1, 2, 3],
[4, 5, 6]])
second_column = grid[:, 1]
second_column[0] = 99
print(grid)
# [[ 1 99 3]
# [ 4 5 6]]
If you need independent values, explicitly copy the slice:
second_column_copy = grid[:, 1].copy()
The ndarray reference documents tuple-based indexing and the shared-data behavior of views.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.When should I choose array.array instead?
Use array.array when you want a mutable, one-dimensional sequence whose values are constrained by a basic type code, and you do not need NumPy’s multidimensional or numerical feature set. It is in Python’s standard library:
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
from array import array
values = array('i', [10, 20, 30])
values.append(40)
print(values)
The type code 'i' selects a signed integer type. Type codes identify C-compatible types; the exact size of some codes can depend on the platform, so do not assume every code has a universal byte layout. Consult the Python array documentation for the codes and platform details.
Compatibility note for Python 3.14
In the Python 3.14.7 documentation, type code 'u' is deprecated and scheduled for removal in Python 3.16, while 'w' was added in Python 3.13. Code using either should be checked against the Python versions it needs to support.
What should I use for a “2D array”?
A nested Python list can hold rows, but it remains a list of lists. Choose NumPy’s ndarray when your task needs a multidimensional array with a defined shape and array-oriented numerical operations. Choose nested lists when ordinary sequence behavior is sufficient and you do not need those array features. The standard-library array.array is one-dimensional, so it is not a native 2D-array alternative.
Which NumPy version do these references describe?
The linked NumPy manual identifies itself as version 2.5, with a release date of June 28, 2026. Examples here use broadly established constructor, attribute, indexing, and slicing forms; consult the documentation for the NumPy version installed in your environment if version-specific behavior matters. See the NumPy v2.5 Manual.
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.




