Index slicing help

Index slicing help
0

Can someone explain the codes for these two situations? Any help much appreciated. I’m using a spyder anaconda console if that helps :slight_smile:

  1. Given:
In []: import numpy as np

In []: x = (20*np.random.rand(5, 7))//2

Enter an expression which sets columns 1, 3, and 4 to 1.5. Use advanced indexing combined with slicing for this.

  1. Given:
In []: import numpy as np

In []: x = np.zeros((5, 3))

In []: col = np.arange(5.0) ``

Enter an expression which adds col to column 1 of x.

The first piece of code creates a 2-D array with dimensions 5 x 7 (height x width) and fills the array with with values following a uniform distribution. Looks like they are asking you to set certain buckets in the 2-D array to 1.5.

The second piece of code creates a zero-filled 2-D array with dimensions (5 x 3) and also initializes a variable col to be an array of evenly-spaced values between 0 and 5.0. They are asking you to add this array to the first column of the zero-filled 2-D array.