[Numpy-discussion] Classes as records within an numpy array

David Crisp david.crisp at gmail.com
Sun Apr 10 23:17:25 EDT 2011


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?
>>
>
> You must use dtype=object for the array vegetation_matrix.

I changed the line which set up the vegetation_matrix to be the following:

vegetation_matrix = numpy.empty(shape=(x_bins+1,y_bins+1,),dtype=object)

Then I spotted the next problem.

In my loop which goes through the raw data and populates the matrix
with the required values,  I am constantly resetting the Record() to a
new record.

for each_line in point_scandata:
	matrix_x = round_to_value((each_line[0]-x_offset),horizontal_precision)
	matrix_y = round_to_value((each_line[1]-y_offset),horizontal_precision)
--> 	vegetation_matrix[matrix_x,matrix_y] = Record() # This is wrong:
Everytime its called it resets the record back to default new..
	vegetation_matrix[matrix_x,matrix_y].add(each_line[2]

This means that there is always only 1 entry in the record as its
always being reset after each iteration.

How do I go about setting up the numpy array such that its default
record is Record()

(Im sure this IS a brain fade as It seems really familliar)

Regards,
David



More information about the NumPy-Discussion mailing list