[Numpy-discussion] Setting numpy record array elements
Sameer DCosta
sameerslists at gmail.com
Mon Aug 20 09:34:53 EDT 2007
Hi,
In the example below I have a record array *a* that has a column
*col1". I am trying to set the first element of a.col1 to zero in two
different ways.
1. a[0].col1 = 0 (This fails silently)
2. a.col1[0] = 0 (This works fine)
I am using the latest svn version of numpy. Is this a bug? or is the
first method supposed to fail? If it is supposed to fail should it
fail silently?
Thanks in advance for any replies.
Cheers,
Sameer
%%%% Example Code %%%
import numpy
print numpy.__version__
a = numpy.rec.fromrecords( [ (1,2,3), (4,5,6)],
dtype=[("col1", "<i4"), ("col2", "<i4"), ("col3", "<i4")])
print "a = %s" % a.__repr__()
print "First element of col1 is %ld" % a.col1[0]
print "Setting first element of col1 to zero using a[0].col1 = 0"
a[0].col1 = 0
print "Result: a.col1[0] = %ld" % a[0].col1
print "Setting first element of col1 to zero using a.col1[0] = 0"
a.col1[0] = 0
print "Result: a.col1[0] = %ld" % a[0].col1
%%%% Example Code Output %%%
1.0.4.dev3975
a = recarray([(1, 2, 3), (4, 5, 6)],
dtype=[('col1', '<i4'), ('col2', '<i4'), ('col3', '<i4')])
First element of col1 is 1
Setting first element of col1 to zero using a[0].col1 = 0
Result: a.col1[0] = 1
Setting first element of col1 to zero using a.col1[0] = 0
Result: a.col1[0] = 0
More information about the NumPy-Discussion
mailing list