0

I am trying to compare the float in each row and column to a user input (0-255). If the input is within the standard deviation of the float; then I set the values to red. (hence the 255,0,0). I don't understand what this error is iterating through a matrix

  user_input = input("Lorum Ipsum : ") 

  avg_img = sum(images) / len(images)
  std_dev = np.std(avg_img, dtype=np.float64)


  for i in range(0, len(avg_img)): #i is row
    for j in range(0, len(avg_img[i])): #j is column
        if (std_dev[i][j] > (user_input)).any() : 
            avg_img[i][j] = [255.0, 0.0, 0.0]
7
  • Please, replace your image with the actual code. Commented Mar 19, 2020 at 18:20
  • What is std_dev? user_input? Please provide a minimal reproducible example. Commented Mar 19, 2020 at 18:30
  • std_dev = standard deviation of the average value per pixel. user_input is the input a user would enter. Commented Mar 19, 2020 at 18:31
  • Please show how they are defined, a description in word is not sufficient. Most likely there is a significant difference between what you mean std_dev to be, and what it actually is. Commented Mar 19, 2020 at 18:38
  • Hope this helps! Commented Mar 19, 2020 at 18:55

1 Answer 1

1

The error you observe is related to the following piece of code:

std_dev[i][j]

because std_dev is a scalar or single number and does not support indexing.

Possibly, you want to use the axis parameter of np.std() and perhaps you want to use images (or np.array(images)) as input to it.


Also:

  • it may be possible that you would prefer to use np.mean() instead of sum() / len(). It is hard to say without knowing what images is.
  • the result of input() is a string and, quite likely, you do not want to compare a number with a string, but instead you want to convert to say float() or int().
  • please use meaningful names: user_input is a poor choice as it describes more where it originates more than it contains. threshold is a much better name
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.