slicknick
slicknick

Reputation: 21

Creating an array with two sets of values?

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.

Upvotes: 2

Views: 110

Answers (1)

ansev
ansev

Reputation: 30920

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]]

Upvotes: 1

Related Questions