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] |
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 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started