Machine Learning Prerequisites (Numpy)

You are currently auditing this course.
22 / 32

Numpy - Flattening a NumPy Array (converting to 1-D array) using ravel() function

If you have a multi-dimensional Numpy array, say, a 3-D, 2-D, etc. array, you can convert it to a 1-dimensional (1-D) array using Numpy function ravel().

You may need to do this, as some of the libraries need the data to be fed in 1-dimensional form.

INSTRUCTIONS

Please follow the below steps:

(1) Import numpy as np

(2) Please create a 2-dimensional Numpy array (of size 4x5) called my_2d_arr as below

my_2d_arr = np.arange(20).reshape(<<your code comes here>>)

(3) Call ravel() function on the above Numpy array (my_2d_arr) to create a 1-dimensional array, and store this 1-D array in a variable called my_1d_arr

<<your code comes here>> = my_2d_arr.ravel()

(4) Print this my_1d_arr array by using print() function to see its value

print(<<your code comes here>>)
See Answer

No hints are availble for this assesment

Loading comments...