From lists to multidimensional arrays

If a list containing numeric or textual objects is rendered into a unidimensional array (that could represent a coefficient vector, for instance), a list of lists translates into a two-dimensional array, and a list of list of lists becomes a three-dimensional one:

In: import numpy as np    # Transform a list into a bidimensional array    a_list_of_lists = [[1,2,3],[4,5,6],[7,8,9]]    Array_2D = np.array(a_list_of_lists )    Array_2DOut: array([[1, 2, 3],            [4, 5, 6],            [7, 8, 9]])

As mentioned previously, you can call out single values with indices, as in a list, though here you'll have two indices—one for the row dimension (also called axis 0) and one for the column dimension (axis 1):

In: Array_2D[1, 1]Out: 5

Two-dimensional ...

Get Python Data Science Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.