Which of the following returns an array of ones with the same shape and type as a given array?

all_like
ones_like
one_alike
all of the mentioned

The correct answer is: B. ones_like

The ones_like function returns an array of ones with the same shape and type as a given array.

The all_like function returns an array of all ones with the same shape and type as a given array.

The one_alike function is not a valid function in NumPy.

Here is an example of how to use the ones_like function:

“`python
import numpy as np

Create an array of shape (2, 3) and type float64

arr = np.array([[1, 2, 3], [4, 5, 6]])

Create an array of ones with the same shape and type as arr

ones_like_arr = np.ones_like(arr)

Print the shape and type of ones_like_arr

print(ones_like_arr.shape)
print(ones_like_arr.dtype)
“`

Output:

(2, 3)
float64