0

I created an array using numpy.empty(). Now I want to add new values to that array based on the if-else condition. I wrote a for loop for that with the if-else condition inside. I only want to add values to the columns belonging to the first row. But after running the code I've written below, I'm getting some random values in the asr matrix instead of 1 and 0.

My code:

number_rows = 16
number_cols = 10
asr = np.empty((number_rows, number_cols))
 
for i in range(10): 
  if prediction[i] == check_keep[i]:
    asr[0][i] = 1 
  else:
    asr[0][i] = 0 
 
asr

I'd appreciate any help here.

1
  • Use np.zeros or np.ones, np.empty initialises with random numbers Commented Oct 19, 2022 at 5:04

1 Answer 1

1

Use np.zeros or np.ones, np.empty initialises with random numbers

number_rows = 16
number_cols = 10
asr = np.zeros((number_rows, number_cols)) #np.zeros instead
 
for i in range(10): 
  if prediction[i] == check_keep[i]:
    asr.iloc[0, i] = 1 #also it is better to use np indexing here
  else:
    asr.iloc[0, i] = 0 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.