Write a NumPy program to remove all rows in a NumPy array that contain non-numeric values

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

Write a NumPy program to remove all rows in a NumPy array that contain non-numeric values.

 

الأجوبة

import numpy as np
x = np.array([[1,2,3], [4,5,np.nan], [7,8,9], [True, False, True]])
print("Original array:")
print(x)
print("Remove all non-numeric elements of the said array")
print(x[~np.isnan(x).any(axis=1)])

Sample Output:

Original array:                                                        
[[  1.   2.   3.]                                                      
 [  4.   5.  nan]                                                      
 [  7.   8.   9.]                                                      
 [  1.   0.   1.]]                                                     
Remove all non-numeric elements of the said array                      
[[ 1.  2.  3.]                                                         
 [ 7.  8.  9.]                                                         
 [ 1.  0.  1.]]
هل كان المحتوى مفيد؟

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

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