w3resource logo

:

Python Exercises

Python NumPy: Create an array of 10's with the same shape and type of an given array

Python NumPy: Array Object Exercise-41 with Solution

Write a Python program to create an array of 10's with the same shape and type of an given array.
Sample array: x = np.arange(4, dtype=np.int64).

Sample Solution:-

Python Code:

import numpy as np
x = np.arange(4, dtype=np.int64)
y = np.full_like(x, 10)
print(y)

Sample Output:

[10 10 10 10]

Python Code Editor:

Improve this sample solution and post your code through Disqus