[Numpy-discussion] Classes as records within an numpy array
david.crisp at gmail.com
Sun Apr 10 23:40:27 EDT 2011
On Mon, Apr 11, 2011 at 1:17 PM, David Crisp <david.crisp at gmail.com> wrote:
> On Mon, Apr 11, 2011 at 11:00 AM, Sturla Molden <sturla at molden.no> wrote:
>> Den 11.04.2011 02:01, skrev David Crisp:
>>> Can anybody guide me through this problem?
I dont know how acceptable it is to answer your own question :P here goes:
TO some extent I have solved my problem, But I am unsure if it is the
correct way of solving it:
for each_line in point_scandata:
matrix_x = round_to_value((each_line-x_offset),horizontal_precision)
matrix_y = round_to_value((each_line-y_offset),horizontal_precision)
if vegetation_matrix[matrix_x,matrix_y] == None:
vegetation_matrix[matrix_x,matrix_y] = Record()
I added the IF check. If vegetation_matrix[matrix_x,matrix_y] is
still equal to None then that means the record for that grid cell has
not been created yet.
So if it IS none then simply create a record.
If vegetation_matrix[matrix_x,matrix_y] is NOT None then the only
other value it could be is Record (Major Assumption that nobody else
has fiddled with the code) and so simply add a new value to the
record with the appropriate value.
It works but is it the correct way of doing things...
More information about the NumPy-Discussion