First page Back Continue Last page Overview Graphics

Arrays in NumPy

Creating Arrays (ndarray):

>>> a = np.array([42,56,98,77])

>>> a

array([42, 56, 98, 77])

>>> a = np.array([42,56,98,77], float)

>>> x = np.array(42)

>>> x

array(42)

>>> np.array([1, 1, 2, 3, 5, 8, 13, 21])

array([ 1, 1, 2, 3, 5, 8, 13, 21])

>>> np.array([3.4, 6.9, 99.8, 12.8])

Array([ 3.4, 6.9, 99.8, 12.8])

>>> A = np.array([ [3.4, 8.7, 9.9], [1.1, -7.8, -0.7], [4.1, 12.3, 4.8]])

>>> A

array([[ 3.4, 8.7, 9.9],

[ 1.1, -7.8, -0.7],

[ 4.1, 12.3, 4.8]])

optional

Arrays are the central component of NumPy.

The data object „ndarray“ is an n-dimensional array object in NumPy.

In contrast to Python lists, elements of an narray have to be homogeneous, i.e. all elements are of the same type: float or int.