Question: Question in numpy (Vectorized comparison) (usejupyter notebook) In [2]: import numpy as np In [ ]: np.random.seed(0) START YOUR CODE # Create a 3 by

Question in numpy (Vectorized comparison) (usejupyter notebook)

In [2]: import numpy as np

In [ ]: np.random.seed(0)

START YOUR CODE

# Create a 3 by 3 numpy array with random float numbers sampledfrom a normal distribution (mean=0, std=1)

a = None

# Find how many elements are greater than or equal to 0.5 inarray a.

# Hint: numpy array can be directly compared with constantnumbers; In Python, True == 1, and False == 0

count = None

# Find the indices of all elements in array a that are greaterthan or equal to 0.5

# Hint: use np.argwhere()

indices = None

END YOUR CODE

## DO NOT CHANGE THE CODE BELOW ##

assert isinstance(a, np.ndarray)

print('a = {}'.format(a))

print('count = {}'.format(count))

print('indices = {}'.format(indices))

Expected output

a =

[[ 1.76405235 0.40015721 0.97873798]
[ 2.2408932 1.86755799 -0.97727788]
[ 0.95008842 -0.15135721 -0.10321885]]

count =

5

indices =

[[0, 0], [0, 2], [1, 0], [1, 1], [2, 0]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem you can use the following code import numpy as np ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!