arrays - ValueError: invalid literal for int() with base 10: '-' (Python) -


I was trying to convert an array to an integer, and it should have been easy. But I have come up with this error:

  traceback (last most recent call): file "C: \ user \ jo \ desktop \ box" (running) .p " Line 32, & lt; Module & gt; Pixel = [Map] for array in array (int, x) ValueError: Invalid binding for int () with base 10: '-'  

The problem is that I am reading a file, it is an ascii grid, which assigns the -9999 number to the no_data value (this is because the focus in editing Very easy to do.) I can use a regex to convert these values ​​to other people, but I do not want to, so I am thinking that this is just a difference in my code or if I do not Thinking someone can tell a solution?

Code:

  im = open ('input.txt', 'r') imgx = 1452 imgy = 1 9 16 array = [] for IM with open ("qqqf.txt", "r"): array.print (line) print array pixels = [map for x in the array (e) T, X)]  

Input file:

  -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 - 9999 - 9999 - 9999 - 9999 - 9999 1 1 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999 - 9999  

you were confused with the map and the list's understanding

  pixels = [array in array for max (int, x) x]  

Here you take every element of the array , name it X and then every element in the function int to x . But x is a string, and its element is a letter, so you apply int to '-' , then 9 ', then ' 9 ' and therefore a ...

What you just wanted to do was

  Pixels = Map (int, array)  

Also, if every row of your file has many numbers, you

  array.append (line )  

For

  array.append (line.split ())  

Or with one of you End will look like array [ '- 99 9 -999-99 9' -999 -999-99 9]


Comments