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 reinstallCrashes, 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 minuteFor a NumPy array, pass the list to np.array(): arr = np.array(values). A flat list becomes a one-dimensional array; nested lists become multidimensional. Python also has a separate built-in array.array type for compact sequences of constrained basic values.
Convert a list to a NumPy array
NumPy’s ndarray is the usual choice for numerical work, especially when you need multidimensional arrays. Install NumPy if needed, then import it and call np.array() with your list:
import numpy as np
values = [1, 2, 3]
arr = np.array(values)
print(arr)
The result is a one-dimensional NumPy array containing the list’s values.
Choose dimensions from the list structure
NumPy uses the nesting of the input list to determine the array’s dimensions. A flat list produces a 1D array, a list of lists produces a 2D array, and deeper nesting produces further dimensions.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
import numpy as np
one_dimensional = np.array([1, 2, 3])
two_dimensional = np.array([[1, 2], [3, 4]])
The second example has two rows and two columns. For consistent dimensions, nested lists should have matching lengths; irregular nesting may not form the regular multidimensional array you intended.
Control the element type with dtype
Without an explicit type, NumPy infers a dtype from the values. When a list mixes numeric types, NumPy may promote them to a common type: for example, [1, 2, 3.0] becomes an array of floating-point values.
Rank #2
Specify dtype when the representation matters:
arr_float = np.array([1, 2, 3], dtype=float)
arr_int32 = np.array([1, 2, 3], dtype=np.int32)
A constrained dtype may not represent every input value. NumPy’s dtype guide demonstrates that assigning 128 to an int8 value raises an overflow error. Choose a type that can hold the values you expect rather than assuming conversion will preserve out-of-range numbers.
Use Python’s built-in array.array for basic values
If you do not need NumPy’s multidimensional numerical arrays, Python’s standard library includes array.array. It stores a sequence of basic values constrained by a one-character type code. For example, 'd' selects double-precision floating-point values:
from array import array
values = [1.0, 2.0, 3.0]
arr = array('d', values)
This is a distinct type from NumPy’s ndarray, not a direct replacement for its multidimensional arrays. Choose between them based on the operation: use NumPy for multidimensional numerical work and its array operations; use array.array when a sequence of a particular basic value type is what you need.
Quick Recap
Best Value
Quick comparison
| Type | How to create it from a list | Best fit |
|---|---|---|
NumPy ndarray |
np.array(values) |
Numerical work, multidimensional arrays, and explicit NumPy dtype handling. |
Python array.array |
array('d', values) for double-precision floats; choose a type code for the required basic value type. |
A sequence of constrained basic values in the standard library. |
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.




