We can create a numpy array of any dimension we want simply by giving it an argument of that dimension (2D, 3D, etc).
Note that the second example uses a tuple as an argument, which also works. arr = np.array()īoth of which give us the following array: We can create a regular 1-dimensional (1d) array by giving the np.array function a list as an argument. That’s simple enough, but not very useful. The result is an array that contains just one number: 4. Here we use the np.array function to initialize our array with a single argument ( 4 ). Let’s start with the simplest one: an array of zero dimensions (0d), which contains a single element.
There are many ways of creating a Numpy array.