I am looking for a little assistance in slicing a (1050,1) array of temperatures.

I have 2 temperature ranges T1-T2 and T2-T3 that i want to slice from the array using boolean slicing. How do I go about this?

Dan

Recommended Answers

All 2 Replies

Slice what? which part???? can you please provide more info and any code you have .

:)

Let's say you have the array as a list. Here's a possible solution:

# This solution's assuming you have values for bounds that match values in the range you have.
T = range(0, 101) # Arbitrary list of temperatures.
T1 = 5 # Arbitrary first lower bound.
T2 = 35 # Arbitrary first upper bound.
T3 = 50 # Arbitrary second lower bound
T4 = 75 # Arbitrary second upper bound

# Slicing is as follows:

T1s = T[T.index(T1): T.index(T2) + 1] # First sub-list containing temperatures in the first range, inclusive.

T2s = T[T.index(T3): T.index(T4) + 1] # Second sub-list containing temperatures in the second range, inclusive.

# The following solution's assuming you don't have values for bounds that match values in the range you have, but you still want temperatures in that range. It uses the same naming convention as above.

T = range(0, 101) # Arbitrary list of temperatures.
T1 = 5 # Arbitrary first lower bound.
T2 = 35 # Arbitrary first upper bound.
T3 = 50 # Arbitrary second lower bound
T4 = 75 # Arbitrary second upper bound

# But now let's assume T1, T2, T3, and T4 aren't in T. So:

x = T[0]

while x < T1:
    for m in T:
        if m > T1:
           T1 = m
    x = m

y = T[len(T) - 1]

while y > T2:
    for m in T:
       if m < T2:
            T2 = m
    y = m

# The process will be the same for T3 and T4. Then:

T1s = T[T.index(T1): T.index(T2) + 1] # First sub-list containing temperatures in the first range, inclusive.

T2s = T[T.index(T3): T.index(T4) + 1] # Second sub-list containing temperatures in the second range, inclusive.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.