Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

python - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...