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])
Question
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])
Solution
The correct answer is d. array([1, 1, 1, 1])
The numpy function ones_like takes an array-like input and returns a new array of the same shape and type, filled with ones. So, regardless of the values in the input array ([12, 13, 14, 15] in this case), the output will be an array of the same size but with all elements as 1.
Similar Questions
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]))
Analyse the following code and predict the output.list1 = [2,4,6,8,10,12,14,16,18,20]print (list1[0:1],list1[5:7])Select one:Error[2] [12, 14][4][14,16][2][12,14,16]
What does ones_like() function do?Select one:None of themReturn an array of ones with the same type as a given arrayReturn an array of ones with the same shape as a given arrayReturn an array of ones with the same shape and type as a given array
A=1/15(3 -13 8, 12 -7 2, -12 17 -7), B=(1 3 2, 4 5 6, 8 7 9), Multiply matrix A with B and also B with A
What will the following code generate?for i in range(0, 12, 3): print(i)A.0 1 2 3 4 5 6 7 8 9 10 11B.0 3 6 9C.0 1 2 3 4 5 6 7 8 9 10 11 12D.0 3 6
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.