Write a NumPy program to create an array of equal shape and data type of a given array

  • برمجة بايثون

Write a NumPy program to create an array of equal shape and data type of a given array.
Fill the new array with 0.0.

الأجوبة

import numpy as np  
nums = np.array([[5.54, 3.38, 7.99],
              [3.54, 8.32, 6.99],
              [1.54, 2.39, 9.29]])
print("Original array:")
print(nums)
print("\nNew array of equal shape and data type of the said array filled by 0:")
print(np.zeros_like(nums))

Sample Output:

Original array:
[[5.54 3.38 7.99]
 [3.54 8.32 6.99]
 [1.54 2.39 9.29]]

New array of equal shape and data type of the said array filled by 0:
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...