Creating a multidimensional array

Now that we know how to create a vector, we are set to create a multidimensional NumPy array. After we produce the matrix, we will again need to show its shape (check arrayattributes.py from this book's code bundle), as demonstrated in the following code snippets:

  1. Create a multidimensional array as follows:
    In: m = array([arange(2), arange(2)])
    In: m
    Out:
    array([[0, 1],
           [0, 1]])
  2. Show the array shape as follows:
    In: m.shape
    Out: (2, 2)

We made a 2 x 2 array with the arange() subroutine. The array() function creates an array from an object that you pass to it. The object has to be an array, for example, a Python list. In the previous example, we passed a list of arrays. The object is the only required parameter of the ...

Get Python Data Analysis 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.