🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.array.html
numpy.array — NumPy v2.5 Manual
Specifies the minimum number of dimensions that the resulting array should have. Ones will be prepended to the shape as needed to meet this requirement. ... Specifies the maximum number of dimensions to create when inferring shape from nested sequences. By default (ndmax=0), NumPy recurses ...
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
NumPy is used to work with arrays. The array object in NumPy is called ndarray.
Discussions

Why one should always use Numpy arrays over built-in lists for mathematical operations, especially for relatively small square matrices.
not always. if it makes the code uglier and the optimization provides no real-life benefit, it is a mistake. The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming. --Donald Knuth More on reddit.com
🌐 r/Python
24
170
May 3, 2020
What are the differences between Python Array, Numpy Array and Panda Dataframe? When do I use which?
Python array the term is "Python list" usage: everyday plain Python code NumPy array: data manipulation that needs to be fast can use Python lists if speed isn't a concern supports fast and convenient vectorized functions: write np.sqrt(array) instead of [math.sqrt(number) for number in your_list] elegantly handles arbitrary number of dimensions Pandas dataframe: for data wrangling in SQL-like language similar to in-memory SQLite database supports NumPy's vectorized functions basically a glorified NumPy array with column names More on reddit.com
🌐 r/AskProgramming
24
5
October 10, 2021
🌐
NumPy
numpy.org › doc › stable › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.5 Manual
NumPy (Numerical Python) is an open source Python library that’s widely used in science and engineering. The NumPy library contains multidimensional array data structures, such as the homogeneous, N-dimensional ndarray, and a large library of functions that operate efficiently on these data ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › basics-of-numpy-arrays
Basics of NumPy Arrays - GeeksforGeeks
June 16, 2026 - NumPy stands for Numerical Python and is used for handling large, multi-dimensional arrays and matrices. Unlike Python's built-in lists NumPy arrays provide efficient storage and faster processing for numerical and scientific computations.
numerical programming package for the Python programming language
NumPy (pronounced /ˈnʌmpaɪ/ NUM-py) is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on … Wikipedia
Factsheet
Original author Travis Oliphant
Developer Community project
Release As Numeric, 1995; as NumPy, 2006
Factsheet
Original author Travis Oliphant
Developer Community project
Release As Numeric, 1995; as NumPy, 2006
🌐
NumPy
numpy.org
NumPy
Powerful N-dimensional arrays Fast and versatile, the NumPy vectorization, indexing, and broadcasting concepts are the de-facto standards of array computing today. Numerical computing tools NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more.
🌐
NumPy
numpy.org › doc › stable › reference › arrays.html
Array objects — NumPy v2.5 Manual
Figure Conceptual diagram showing the relationship between the three fundamental objects used to describe the data in an array: 1) the ndarray itself, 2) the data-type object that describes the layout of a single fixed-size element of the array, 3) the array-scalar Python object that is returned when a single element of the array is accessed.#
Find elsewhere
🌐
Molssi
education.molssi.org › python-data-analysis › 01-numpy-arrays › index.html
Working with Numpy Arrays – Python for Data Analysis
April 17, 2022 - You can add two arrays together, multiply arrays by scalars, or do element-wise multiplcation of arrays. For example, you can multiply two numpy arrays to get their element-wise product.
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.02-the-basics-of-numpy-arrays.html
The Basics of NumPy Arrays | Python Data Science Handbook
Data manipulation in Python is nearly synonymous with NumPy array manipulation: even newer tools like Pandas (Chapter 3) are built around the NumPy array. This section will present several examples of using NumPy array manipulation to access data and subarrays, and to split, reshape, and join ...
Top answer
1 of 7
487

Numpy matrices are strictly 2-dimensional, while numpy arrays (ndarrays) are N-dimensional. Matrix objects are a subclass of ndarray, so they inherit all the attributes and methods of ndarrays.

The main advantage of numpy matrices is that they provide a convenient notation for matrix multiplication: if a and b are matrices, then a*b is their matrix product.

import numpy as np

a = np.mat('4 3; 2 1')
b = np.mat('1 2; 3 4')
print(a)
# [[4 3]
#  [2 1]]
print(b)
# [[1 2]
#  [3 4]]
print(a*b)
# [[13 20]
#  [ 5  8]]

On the other hand, as of Python 3.5, NumPy supports infix matrix multiplication using the @ operator, so you can achieve the same convenience of matrix multiplication with ndarrays in Python >= 3.5.

import numpy as np

a = np.array([[4, 3], [2, 1]])
b = np.array([[1, 2], [3, 4]])
print(a@b)
# [[13 20]
#  [ 5  8]]

Both matrix objects and ndarrays have .T to return the transpose, but matrix objects also have .H for the conjugate transpose, and .I for the inverse.

In contrast, numpy arrays consistently abide by the rule that operations are applied element-wise (except for the new @ operator). Thus, if a and b are numpy arrays, then a*b is the array formed by multiplying the components element-wise:

c = np.array([[4, 3], [2, 1]])
d = np.array([[1, 2], [3, 4]])
print(c*d)
# [[4 6]
#  [6 4]]

To obtain the result of matrix multiplication, you use np.dot (or @ in Python >= 3.5, as shown above):

print(np.dot(c,d))
# [[13 20]
#  [ 5  8]]

The ** operator also behaves differently:

print(a**2)
# [[22 15]
#  [10  7]]
print(c**2)
# [[16  9]
#  [ 4  1]]

Since a is a matrix, a**2 returns the matrix product a*a. Since c is an ndarray, c**2 returns an ndarray with each component squared element-wise.

There are other technical differences between matrix objects and ndarrays (having to do with np.ravel, item selection and sequence behavior).

The main advantage of numpy arrays is that they are more general than 2-dimensional matrices. What happens when you want a 3-dimensional array? Then you have to use an ndarray, not a matrix object. Thus, learning to use matrix objects is more work -- you have to learn matrix object operations, and ndarray operations.

Writing a program that mixes both matrices and arrays makes your life difficult because you have to keep track of what type of object your variables are, lest multiplication return something you don't expect.

In contrast, if you stick solely with ndarrays, then you can do everything matrix objects can do, and more, except with slightly different functions/notation.

If you are willing to give up the visual appeal of NumPy matrix product notation (which can be achieved almost as elegantly with ndarrays in Python >= 3.5), then I think NumPy arrays are definitely the way to go.

PS. Of course, you really don't have to choose one at the expense of the other, since np.asmatrix and np.asarray allow you to convert one to the other (as long as the array is 2-dimensional).


There is a synopsis of the differences between NumPy arrays vs NumPy matrixes here.

2 of 7
107

Scipy.org recommends that you use arrays:

*'array' or 'matrix'? Which should I use? - Short answer

Use arrays.

  • They support multidimensional array algebra that is supported in MATLAB
  • They are the standard vector/matrix/tensor type of NumPy. Many NumPy functions return arrays, not matrices.
  • There is a clear distinction between element-wise operations and linear algebra operations.
  • You can have standard vectors or row/column vectors if you like.

Until Python 3.5 the only disadvantage of using the array type was that you had to use dot instead of * to multiply (reduce) two tensors (scalar product, matrix vector multiplication etc.). Since Python 3.5 you can use the matrix multiplication @ operator.

Given the above, we intend to deprecate matrix eventually.

🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu › notebooks › chapter02.07-Introducing_numpy_arrays.html
Introducing Numpy Arrays — Python Numerical Methods
In order to use Numpy module, we need to import it first. A conventional way to import it is to use “np” as a shortened name. ... WARNING! Of course, you could call it any name, but conventionally, “np” is accepted by the whole community and it is a good practice to use it for obvious purposes. To define an array in Python, you could use the np.array function to convert a list.
🌐
Jmgphd
jmgphd.com › courses › csc5930 › lecture-notes › numpy-arrays
NumPy Arrays – Jason M. Grant
NumPy arrays are similar to Python lists, though there are some notable differences. The size of a NumPy array must be specified at creation and cannot be changed. Furthermore, all elements of a NumPy array, unlike a list, must be of the same data type. What NumPy loses in flexibility, it gains ...
🌐
NumPy
numpy.org › doc › 2.4 › reference › arrays.html
Array objects — NumPy v2.4 Manual
Figure Conceptual diagram showing the relationship between the three fundamental objects used to describe the data in an array: 1) the ndarray itself, 2) the data-type object that describes the layout of a single fixed-size element of the array, 3) the array-scalar Python object that is returned when a single element of the array is accessed.#
🌐
NumPy
numpy.org › doc › 2.5 › user › basics.creation.html
Array creation — NumPy v2.5 Manual
You can use these methods to create ndarrays or Structured arrays. This document will cover general methods for ndarray creation. NumPy arrays can be defined using Python sequences such as lists and tuples. Lists and tuples are defined using [...] and (...), respectively.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.array.html
numpy.array — NumPy v2.1 Manual
If None, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). Note that any copy of the data is shallow, i.e., for arrays with object dtype, the new array will point to the same objects.
Top answer
1 of 3
10
Python array the term is "Python list" usage: everyday plain Python code NumPy array: data manipulation that needs to be fast can use Python lists if speed isn't a concern supports fast and convenient vectorized functions: write np.sqrt(array) instead of [math.sqrt(number) for number in your_list] elegantly handles arbitrary number of dimensions Pandas dataframe: for data wrangling in SQL-like language similar to in-memory SQLite database supports NumPy's vectorized functions basically a glorified NumPy array with column names
2 of 3
2
This a great question that also requires a lot of info to cover! I’ll do my best to stay on topic, but there’s so much nuance I might veer off topic a little. Let’s call “Python Arrays” Lists, since that’s mostly how the Python documentation refers to them. Lists are containers which are provided as part of the programming language. Lists are really versatile and Python provides lots of habdy builtin functions you can do with lists. NumPy arrays are indeed very similar to lists, but they were specifically designed for doing lots of number crunching in a very efficient manner. Sure, they can often be used interchangeably with lists, but if you had to calculate something like a Matrix-vector product, and you had to do it millions of times, NumPy would let you do it much faster than you ever could with Lists. Think NumPy arrays as being specialized lists. DataFrames are a bit more complex than both Lists and NumPy Arrays. I’ve seen them compared to spreadsheets quite often, and that’s a good frame of reference for getting started with DataFrames. DataFrames are tabular, like spreadsheet in Excel. Like spreadsheets, DataFrames are useful for cleaning, rearranging, and processing all sorts of data. If you’re interested in seeing DataFrames in action, I highly recommend you check out r/learnmachinelearning ! There are plenty of resources there for getting started. If you’re curious, I can go a bit more into the “why” for each, but I’d prefer to answer specific questions if anyone has any! To summarize: By default, always consider Lists first. They’re a great jack of all trades If you’re doing lots of number crunching, you might benefit for NumPy Arrays. They’re especially good when you need to work with multi-dimensional containers and access them in very specific patterns. DataFrames are more complex than either, but offer the most flexibility and structure. If you need to process something like stock prices, voting records, the CIA World Factbook, or even sometimes application logs, DataFrames can be really handy at providing functionality which you’d otherwise have to add yourself on top of Numpy Arrays or Lists.
🌐
NumPy
numpy.org › doc › stable › user › how-to-partition.html
How to create arrays with regularly-spaced values — NumPy v2.5 Manual
>>> np.linspace(0.1, 0.2, num=5) # np.linspace(start, stop, num) array([0.1 , 0.125, 0.15 , 0.175, 0.2 ]) >>> np.linspace(0.1, 0.2, num=5, endpoint=False) array([0.1, 0.12, 0.14, 0.16, 0.18]) numpy.linspace can also be used with complex arguments:
🌐
NumPy
numpy.org › doc › stable › user › quickstart.html
NumPy quickstart — NumPy v2.5 Manual
Understand axis and shape properties for n-dimensional arrays. NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers.
🌐
DataCamp
datacamp.com › tutorial › python-arrays
Python Arrays: How to Create & Print Arrays using NumPy | DataCamp
August 8, 2024 - Python’s array module provides basic functionality for creating compact, type-restricted arrays similar to those in languages like C. On the other hand, NumPy arrays offer advanced features such as support for multidimensional arrays, a vast library of mathematical functions, and performance optimizations through vectorization. NumPy is generally preferred for numerical and scientific computing. No, the array module is designed to hold only basic data types like integers, floats, and similar.
🌐
NumPy
numpy.org › devdocs › user › whatisnumpy.html
What is NumPy? — NumPy v2.6.dev0 Manual
It is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, ...