Machine Learning Prerequisites (Numpy)

6 / 32

Numpy - Arrays - Special Types of Arrays - Array with Random Values

Below are few more special NumPy arrays which you can create to contain random values.

For example:

  1. NumPy array with all its elements values as random values (using random.rand() function of NumPy)
  2. NumPy array with all its elements values as uninitialized values (initialized with some random values which you are not aware of - using empty() function of NumPy)
INSTRUCTIONS

Note: Please import numpy as np

(1) NumPy array with all its elements values as random values (using random.rand() function of NumPy)

  • Create your NumPy array by passing the above the desired dimensions of the array (say (3,4)) to random.rand() function below

    my_rand_array = np.random.<<your code comes here>>(3,4)
    

The above NumPy array my_rand_array will have random float values between 0.0 and 1.0

(2) NumPy array with all its elements values as uninitialized values (initialized with some random values which you are not aware of - using the empty() function of NumPy)

  • Create a tuple indicating dimensions of the desired array

    tup_dim = (3, 4)
    
  • Now, create your NumPy array by passing the above tuple (tup_dim) to empty() function below

    my_uninitialized_array = np.empty( <<your code comes here>>)
    

The above NumPy array my_uninitialized_array will be filled with random (also unknown) float values between 0.0 and 1.0

See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...