'How to compare int with list and receive index using np.where?
I am currently trying to get the index position of costShirts where the value in costShirts[0] is the largest number thats still smaller than the user input. I keep running into an error ">= not supported between instances of 'int' and 'list'.
I have been trying to convert orderQuantity into a list but that has not been working either.
costShirts = [[1, 12, 48, 72], [9.19, 6.09, 5.75, 5.35]]
costPrints = [[1, 3, 6, 12, 24, 36, 48, 72, 144, 300, 500, 1000, 2500, 5000, 10000], [15, 10, 8, 5, 2.5, 2, 1.75, 1.5, 1.25, 1, 0.75, 0.65, 0.6, 0.55, 0.5]]
probDemand = [[0, 25, 50, 75, 100, 125, 150, 175], [0.05, 0.15, 0.23, 0.27, 0.15, 0.07, 0.05, 0.03]]
shirtPrice = [15.99]
afterPrice = [5.00]
orderSetup = [200]
orderQuantity = int(input("Enter the order quantity: "))
susDemand = input("Enter the suspected demand: ")
if susDemand == "":
dq = int(np.random.choice(probDemand[0],1,probDemand[1]))
else:
dq = int(susDemand)
shirtPos = max(np.where(orderQuantity >= costShirts[0])[0])
Solution 1:[1]
The error message is actual very helpful in this case. Investigate both sides of that >= expression, and you will find that costShirts[0] is a list. You are trying to do a numpy-style vectorized comparison with a python list, which is not supported.
Two suggestions to correct this: convert costShirts to an ndarray up front (fine if you don't care about allowing the 1st row to be converted to int), or you can convert costShirts[0] to an ndarray in place. Either way the conversion to ndarray is accomplished by np.array(<list>).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | blarg |
