[Numpy-tickets] [NumPy] #266: Problems creating chararrays from numarray chararray objects

NumPy numpy-tickets at scipy.net
Wed Aug 23 12:56:50 CDT 2006


#266: Problems creating chararrays from numarray chararray objects
------------------------+---------------------------------------------------
 Reporter:  faltet      |       Owner:  somebody   
     Type:  defect      |      Status:  new        
 Priority:  normal      |   Milestone:  1.0 Release
Component:  numpy.core  |     Version:  devel      
 Severity:  normal      |    Keywords:             
------------------------+---------------------------------------------------
 Hi,

 I don't know if this is a bug or not, but this represents a change
 over NumPy 0.9.8 and I thought that I should report it

 The next script:

 {{{
 import numpy
 print "numpy version-->", numpy.__version__
 import numarray
 print "numarray version-->", numarray.__version__
 import numarray.strings

 sna=numarray.strings.array(None, itemsize=5, shape=(4,2))
 print "itemsize reported by numpy:", numpy.asarray(sna).itemsize

 sna=numarray.strings.array("a"*40, itemsize=5, shape=(4,2))
 print "itemsize reported by numpy:", numpy.asarray(sna).itemsize
 }}}

 gives the next output in 1.0b2 (also in 1.0b4.dev3053):

 {{{
 numpy version--> 1.0b2
 numarray version--> 1.5.1
 itemsize reported by numpy: 1
 itemsize reported by numpy: 5
 }}}

 where the first itemsize reported by numpy is wrong. However, this
 used to work well in numpy 0.9.8:

 {{{
 numpy version--> 0.9.8
 numarray version--> 1.5.1
 itemsize reported by numpy: 5
 itemsize reported by numpy: 5
 }}}

 FWIW, here is a workaround that allows creating a numpy chararray from
 a numarray chararray buffer:

 {{{
 sna=numarray.strings.array(None, itemsize=5, shape=(4,2))
 dtype = numpy.dtype("|S%s" % sna.itemsize())
 snp=numpy.ndarray(buffer=sna._data, dtype=dtype, shape=sna.shape)
 print "itemsize reported by numpy:", snp.itemsize

 sna=numarray.strings.array("a"*40, itemsize=5, shape=(4,2))
 dtype = numpy.dtype("|S%s" % sna.itemsize())
 snp=numpy.ndarray(buffer=sna._data, dtype=dtype, shape=sna.shape)
 print "itemsize reported by numpy:", snp.itemsize

 }}}

 which gives:

 {{{
 numpy version--> 1.0b2
 numarray version--> 1.5.1
 itemsize reported by numpy: 5
 itemsize reported by numpy: 5
 }}}

 that is what I think is the correct answer.

 Regards,

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/266>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list