0

I am relatively new to python and trying to locate the cell that contains the value "3275" which is here, the "newELA". This value is in the top row of the spreadsheet and is a header. This is what I have been trying:

loc=("/Volumes/Project/Andes_Glacier_Inventory.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(1)
headers = sheet.row(0)[3:]

a = np.array(sheet.row_values(1,3))

value = 501
ELA = headers[np.argmax(a * (a < value))]
print ("The ELA is", ELA.value)

changeinELA = 100
value1 = changeinELA
value2 = ELA.value
newELA = float(value1) + float(value2)
print ("The new ELA is", newELA)

b = np.where (np.array(headers) == newELA)
print (b)

The results I am getting are, which I don't even understand

(array([], dtype=int64),)
4
  • Could you please provide the entire code, such as how the sheet is obtained? Commented Jan 6, 2019 at 11:11
  • Your result seem to be an empy numpy array. Yep, as @Pierre suggested, could you provide more code? Commented Jan 6, 2019 at 11:28
  • edited with all the code I'm currently using Commented Jan 6, 2019 at 11:31
  • b is the indices where the == is true - in this case there aren't any. If you showed us headers and newELA it might help. Commented Jan 6, 2019 at 18:07

2 Answers 2

1

You can see How does python numpy where work?. The value "3275" is a string. On the other hand, you have an array of integers and the newELA is float. You have to decide in which dtype the headers array is and it should be the same with the newELA variable. For example,

import numpy as np
headers = [200, 100, 300]
a = np.array(headers)
b = np.where (a == 300)
print(b)

output

(array([2], dtype=int64),)
Sign up to request clarification or add additional context in comments.

Comments

0

You are getting an empty array because there is nothing in your headers which is equal to your newELA value.

Check your data. Just a thought of what could be your problem: If there is a floating point error, you can do the following:

tol = 1e-10   #change accordingly
b = np.where (np.abs(np.array(headers, dtype=np.float) - newELA) < tol) #passing dtype=np.float will convert your strings, if you need to
print (b) 

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.