简体   繁体   中英

Identification of empty elements of a np.array

I want to do a for-loop over a np.array arr[r,c] with unpredicted NaN and want to identify those in order to impute them specifically according to the context. Could anybody helP?

You should really try to elaborate your question.

If your numpy array is 1D then do the following:

for i in range(arr.shape[0]):
    print(arr[i])

If your numpy array is 2D then do the following:

for i in range(arr.shape[0]):
    for j in range(arr.shape[1]):
        print(arr[i,j])

if you want to denote the 'NaN' values differently. Just use an if statement

if math.isnan(arr[i,j]):
    arr[i,j] = "anything"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM