[英]Removing nan entries from a 2-D Numpy array without for loops
How would I go about removing all arrays that include nan in them from a 2 dimensional Numpy Array?我将如何从二维 Numpy 数组中删除所有包含 nan 的数组? I want to remove the entire array that they are in. I am using Numpy arrays.我想删除它们所在的整个数组。我正在使用 Numpy 数组。
x = [[1400, 1500, 1600, nan, nan, nan ,1700],[1400, 1500, 1600, 1800, 1900, 2000 ,1700],[1400, 1500, 1600, nan, nan, nan ,1700]] x = [[1400, 1500, 1600, 南, 南, 南, 1700],[1400, 1500, 1600, 1800, 1900, 2000, 1700],[1400, 1500, 1600], 南, 0, 7 ]
my result for x would be x = [[400, 1500, 1600, 1800, 1900, 2000 ,1700]]我对 x 的结果是 x = [[400, 1500, 1600, 1800, 1900, 2000,1700]]
My main issue as of now is that I am trying to avoid using for loops due to the length of my actual data set到目前为止,我的主要问题是由于实际数据集的长度,我试图避免使用 for 循环
Use x = x[~np.isnan(x).any(axis=1)]
使用x = x[~np.isnan(x).any(axis=1)]
Ref: https://www.w3resource.com/python-exercises/numpy/python-numpy-exercise-91.php参考: https : //www.w3resource.com/python-exercises/numpy/python-numpy-exercise-91.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.