NumPy arrays
An array can be used to contain values of a data object in an experiment or simulation step, pixels of an image, or a signal recorded by a measurement device. For example, the latitude of the Eiffel Tower, Paris is 48.858598 and the longitude is 2.294495. It can be presented in a NumPy array object as p
:
>>> import numpy as np >>> p = np.array([48.858598, 2.294495]) >>> p array([48.858598, 2.294495])
This is a manual construction of an array using the np.array
function. The standard convention to import NumPy is as follows:
>>> import numpy as np
You can, of course, put from numpy import *
in your code to avoid having to write np
. However, you should be careful with this habit because of the potential code conflicts (further information on code conventions can be found in the Python Style Guide, also known as PEP8, at https://www.python.org/dev/peps/pep-0008/).
There are two requirements of a NumPy array: a fixed size at creation and a uniform...