2

I have a feeling that I have been overthinking this, but I have been having trouble with creating a proper array that has one value associated with another.

The list I'm working with:

Solution 1: 2.5 pH, Solution 2: 5.5 pH, Solution 3: 10 pH, Solution 4: 7.2 pH, Solution 5: 9 pH

I am trying to show the pH's that are acidic (<7) with the corresponding solution number.

I created an array: import numpy as np

data_list_numpy = np.array(['2.5','5.5','10','7.2','9'])

Then did this to show pH's below 7: smaller_than_7 = np.empty([0])

for item in data_list_float:

if item <7:

smaller_than_7 = np.append(smaller_than_7,item)

print('Acidic solutions are',smaller_than_7)

How can I create an array for the pH of each solution and use a loop that goes through each element of the array? I want to list the pH's with the corresponding solution number.

1
  • "a proper array that has one value associated with another". You mean, a dict? Commented Mar 29, 2022 at 23:31

1 Answer 1

1

Use:

smaller_than_7 = data_list_numpy[data_list_numpy < 7]

If you want concatenate with int np.r_

smaller_than_7 = np.r_[0, data_list_numpy[data_list_numpy < 7]]
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.