First page Back Continue Last page Overview Graphics

Nested Lists/Tuples

Nested lists or tuples with equal-lengths can be converted into multidimensional arrays:

>>> l = [[1,2,3],[4,5,6],[7,8,9]]

>>> a = np.array(l)

>>> a

array([[1, 2, 3],

[4, 5, 6],

[7, 8, 9]])

>>> lt = ([21,3,9,-4],[11,-3,6,-2],[-77,83,44,9])

>>> a = np.array(lt)

>>> a.ndim

2

>>> a.shape

(3, 4)

>>>

the dimension of the array

the shape of the array