下面的代码是为了检查Python ND数组列中的NaN值而编写的。如果temparr1或temparr2中有一个NaN,我们将从它们中删除相应的行。问题是,它似乎不起作用。你能帮帮我吗?在
temparr1=arr[index[indexkey]][:]// We get a column from arr, an nd-array of size 0 to 9470
temparr2=arr[index[secondIndexKey]][:]// Same as above, but with the next column
rwc=range(0,len(arr)) We get a bit vector of a sort to check.
for i in range(0,len(arr)):
if(isnan(temparr1[i]) or isnan(temparr2[i]) ):
rwc = rwc[:i-1]+rwc[i+1:] // Remove the value from the bit Vector for a NaN value in the arrays.
print i
temparr1 = []
temparr2 = []
for i in rwc:
temparr1.append(arr[index[indexkey]][i])
temparr2.append(arr[index[secondIndexKey]][i])// Extract the data for the corresponding values in RWC and get them into the temparrs.
有人能告诉我为什么它不起作用,为什么我仍然得到南斯??在
数组如下:[99242122,nan,42,nan,414,……………]
在}和{}的相同索引。在
rwc=range(0,len(arr))
之后是len(rwc)=len(arr)
,所以在rwc = rwc[:i-1]+rwc[i+1:]
行中,i
是{但是,在
rwc = rwc[:i-1]+rwc[i+1:]
之后,您将得到一个长度更小的列表(len(rwc) = len(arr) -2
),因此在下一次迭代中,您将开始从列表中删除错误的元素。在我还怀疑您打算做
rwc = rwc[:i]+rwc[i+1:]
,这是另一个bug据我所知你试图做这样的事:
相关问题 更多 >
编程相关推荐