Difficulty: beginner
Estimated Time: 15 minutes

This scenario is the introduction to the basic concepts for the numpy library.

It's not a comprehensive tutorial, but enough to follow the next scenarios in the Deep Learning course.

Congratulations!

You've completed Numpy Basics scenario.

You've learned the following concepts using Python numpy library:

  • Creating the array
  • Operations on arrays
  • Applying functions
  • Perform linear algebra operations

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Numpy Basics

Step 1 of 4

Creating the arrays

Numpy package is one the most widely used library in the Python environment. It enables straightforwardly vectorising the operations. In the world of Deep Learning and Neural Networks, this is a desirable quality.

Numpy's main object is a multidimensional array storing elements of the same type, usually numbers. The arrays (umpy.array) created using the library differ from the ones in Python standard library (array.array). Let us first run the Python command line and import the package.

python

import numpy as np

There are several ways on how to create the arrays. The easiest is to provide the set of value, by passing a regular Python list or tuple using the array function.

np.array([2, 4, 15]) np.array([[1, 2], [3, 4], [5, 6]])

The transformations change sequences of sequences into two-dimensional arrays, sequences of sequences of sequences into three-dimensional arrays, and so on. Notice that the following line will return with the error:

np.array(2, 4, 15)

To find out about the shape of the array use the following:

a = np.array([[1, 2], [3, 4], [5, 6]]) a.shape

To change it, use the reshape function:

a.reshape(2, 3)

You may find the functions zeros and ones useful to create arrays containing only 0s or 1s:

np.zeros((3, 4)) np.ones((2, 3))

For the randomly generated numbers apply:

np.random.random((2,3))