The NumPy array: a structure for efficient numerical computation
Computing in Science Engineering (2011)
- DOI: 10.1109/MCSE.2011.37
- arXiv: 1102.1523
Available from
Stefan van der Walt's profile on Mendeley.
or
Abstract
In the Python world, NumPy arrays are the standard representation for numerical data. Here, we show how these arrays enable efficient implementation of numerical computations in a high-level language. Overall, three techniques are applied to improve performance: vectorizing calculations, avoiding copying data in memory, and minimizing operation counts. We first present the NumPy array structure, then show how to use it for efficient computation, and finally how to share array data with other libraries.
Page 1
The NumPy array: a structure for efficient numerical computation
ar
X
iv
:1
10
2.
15
23
v1
[
cs
.M
S]
8
Fe
b 2
01
1
The NumPy array: a structure for efficient
numerical computation
Stéfan van der Walt, Stellenbosch University South Africa
S. Chris Colbert, Enthought USA
Gael Varoquaux, INRIA Saclay France
This article is published in IEEE Computing in Science and Engineering. Please refer to
the published version if accessible, as it contains editor’s improvements. (c) 2011 IEEE.∗
In the Python world, NumPy arrays are the stan-
dard representation for numerical data. Here, we
show how these arrays enable efficient implemen-
tation of numerical computations in a high-level
language. Overall, three techniques are applied
to improve performance: vectorizing calculations,
avoiding copying data in memory, and minimizing
operation counts.
We first present the NumPy array structure, then
show how to use it for efficient computation, and
finally how to share array data with other li-
braries.
Introduction
The Python programming language provides a
rich set of high-level data structures: lists for enu-
merating a collection of objects, dictionaries to
build hash tables, etc. However, these structures
are not ideally suited to high-performance numer-
ical computation.
In the mid-90s, an international team of volun-
teers started to develop a data-structure for effi-
cient array computation. This structure evolved
into what is now known as the N-dimensional
NumPy array.
The NumPy package, which comprises the
NumPy array as well as a set of accompanying
mathematical functions, has found wide-spread
adoption in academia, national laboratories, and
industry, with applications ranging from gaming
to space exploration.
∗Personal use of this material is permitted. Permission
from IEEE must be obtained for all other users, includ-
ing reprinting/ republishing this material for advertising
or promotional purposes, creating new collective works for
resale or redistribution to servers or lists, or reuse of any
copyrighted components of this work in other works.
A NumPy array is a multidimensional, uniform
collection of elements. An array is character-
ized by the type of elements it contains and by
its shape. For example, a matrix may be repre-
sented as an array of shape (M ×N) that contains
numbers, e.g., floating point or complex numbers.
Unlike matrices, NumPy arrays can have any
dimensionality. Furthermore, they may contain
other kinds of elements (or even combinations of
elements), such as booleans or dates.
Underneath the hood, a NumPy array is really
just a convenient way of describing one or more
blocks of computer memory, so that the numbers
represented may be easily manipulated.
Basic usage
Throughout the code examples in the article,
we assume that NumPy is imported as follows:
import numpy as np
Code snippets are shown as they appear inside an
[IPython] prompt, such as this:
In [3]: np.__version__
Out [3]: ’1.4.1’
Elements contained in an array can be indexed us-
ing the [] operator. In addition, parts of an array
may be retrieved using standard Python slicing
of the form start:stop:step. For instance, the
first two rows of an array x are given by x[:2, :]
or columns 1 through 3 by x[:, 1:4]. Similarly,
every second row is given by x[::2, :]. Note
that Python uses zero-based indexing.
1
X
iv
:1
10
2.
15
23
v1
[
cs
.M
S]
8
Fe
b 2
01
1
The NumPy array: a structure for efficient
numerical computation
Stéfan van der Walt, Stellenbosch University South Africa
S. Chris Colbert, Enthought USA
Gael Varoquaux, INRIA Saclay France
This article is published in IEEE Computing in Science and Engineering. Please refer to
the published version if accessible, as it contains editor’s improvements. (c) 2011 IEEE.∗
In the Python world, NumPy arrays are the stan-
dard representation for numerical data. Here, we
show how these arrays enable efficient implemen-
tation of numerical computations in a high-level
language. Overall, three techniques are applied
to improve performance: vectorizing calculations,
avoiding copying data in memory, and minimizing
operation counts.
We first present the NumPy array structure, then
show how to use it for efficient computation, and
finally how to share array data with other li-
braries.
Introduction
The Python programming language provides a
rich set of high-level data structures: lists for enu-
merating a collection of objects, dictionaries to
build hash tables, etc. However, these structures
are not ideally suited to high-performance numer-
ical computation.
In the mid-90s, an international team of volun-
teers started to develop a data-structure for effi-
cient array computation. This structure evolved
into what is now known as the N-dimensional
NumPy array.
The NumPy package, which comprises the
NumPy array as well as a set of accompanying
mathematical functions, has found wide-spread
adoption in academia, national laboratories, and
industry, with applications ranging from gaming
to space exploration.
∗Personal use of this material is permitted. Permission
from IEEE must be obtained for all other users, includ-
ing reprinting/ republishing this material for advertising
or promotional purposes, creating new collective works for
resale or redistribution to servers or lists, or reuse of any
copyrighted components of this work in other works.
A NumPy array is a multidimensional, uniform
collection of elements. An array is character-
ized by the type of elements it contains and by
its shape. For example, a matrix may be repre-
sented as an array of shape (M ×N) that contains
numbers, e.g., floating point or complex numbers.
Unlike matrices, NumPy arrays can have any
dimensionality. Furthermore, they may contain
other kinds of elements (or even combinations of
elements), such as booleans or dates.
Underneath the hood, a NumPy array is really
just a convenient way of describing one or more
blocks of computer memory, so that the numbers
represented may be easily manipulated.
Basic usage
Throughout the code examples in the article,
we assume that NumPy is imported as follows:
import numpy as np
Code snippets are shown as they appear inside an
[IPython] prompt, such as this:
In [3]: np.__version__
Out [3]: ’1.4.1’
Elements contained in an array can be indexed us-
ing the [] operator. In addition, parts of an array
may be retrieved using standard Python slicing
of the form start:stop:step. For instance, the
first two rows of an array x are given by x[:2, :]
or columns 1 through 3 by x[:, 1:4]. Similarly,
every second row is given by x[::2, :]. Note
that Python uses zero-based indexing.
1
Sign up today - FREE
Mendeley saves you time finding and organizing research. Learn more
- All your research in one place
- Add and import papers easily
- Access it anywhere, anytime
Start using Mendeley in seconds!
Readership Statistics
37 Readers on Mendeley
by Discipline
19% Physics
by Academic Status
38% Ph.D. Student
19% Post Doc
8% Researcher (at a non-Academic Institution)
by Country
35% United States
8% Canada
8% Australia



