Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

To solve this problem you can use the following code import numpy as np ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Human Resource Management

Authors: Lloyd Byars, Leslie Rue

10th Edition

73530557, 978-0071220668, 71220666, 978-0073530550

More Books

Students also viewed these Programming questions

Question

What is an applicant diversity chart?

Answered: 1 week ago