Knowee
Questions
Features
Study Tools

import numpy as np    b = np.array([12, 90, 380, 12, 211])    print(np.where(b>12))    c = np.array([[20, 24],[21, 23]])    print(np.where(c>20))  Output:(array([1, 2, 4]),)(array([0, 1, 1]), array([1, 0, 1]))

Question

import numpy as np    b = np.array([12, 90, 380, 12, 211])    print(np.where(b>12))    c = np.array([[20, 24],[21, 23]])    print(np.where(c>20))  Output:(array([1, 2, 4]),)(array([0, 1, 1]), array([1, 0, 1]))

🧐 Not the exact question you are looking for?Go ask a question

Solution

The code you provided is written in Python, specifically using the numpy library.

The np.where() function is used to check the condition specified and return the indices where the condition is true.

In the first part of the code, np.where(b>12) is checking for the indices in array b where the value is greater than 12. The output (array([1, 2, 4]),) means that the values at indices 1, 2, and 4 in array b are greater than 12.

In the second part of the code, np.where(c>20) is checking for the indices in array c where the value is greater than 20. The output (array([0, 1, 1]), array([1, 0, 1])) is a tuple of two arrays. The first array represents the row indices and the second array represents the column indices. So, the values greater than 20 in array c are at positions (0,1), (1,0), and (1,1).

This problem has been solved

Similar Questions

Example Array:arr =np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])Use the example array 'arr' to answer the following question:To select [4,5,6] from arr, we do _____.

Predict the output for ones_like([12, 13, 14, 15]) ?Select one:a.array([12, 13, 14, 15])b.array([1.0, 1.0, 1.0, 1.0])c. array[12, 13, 14, 15]d.array([1, 1, 1, 1])

Output of the below snippet: import numpy as np a=np.array([100,2,300,]) print(a[0],a[2])

import numpy as npnp_marks = np.array( [23, 21, 18, 25, 12, 18, 10] )print( np_marks[ (np_marks >= 15) ] )

X=np.array([[1,0,1],[2,2,2]]) out=X[0:2,2]

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.