[Numpy-discussion] Quite curious behaviour in Numeric

SIMOND Gilles Gilles.Simond at obs.unige.ch
Thu Apr 7 07:55:08 EDT 2005


 2.6.8-1-686-smp (dilinger at toaster.hq.voxel.net) 
  (gcc version 3.3.4 (Debian 1:3.3.4-9)) 
  #1 SMP Sat Aug 28 12:51:43 EDT 2004:

  and    python2.3

    >>> a=Numeric.ones((2,3),'i')
    >>> b=Numeric.sum(a)+1
    >>> a[1]=b+1
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: Array can not be safely cast to required type
    >>> a.itemsize()
    4
    >>> b.itemsize()
    4
    >>> a.typecode()
    'i'


and e following works

    >>> a=Numeric.ones((2,3))
    >>> b=Numeric.sum(a)+1
    >>> a[1]=b+1
    >>> a.itemsize()
    4
    >>> b.itemsize()
    4
    >>> a.typecode()
    'l'
    
    >>> type(1)
    <type 'int'>

    >>> Numeric.__version__
    '23.6'

  It  seems  that  itemsize()  does  not  return the correct value which
  should  be  8  for  'l'  type array. This is quite annoying since this
  function  is  the  only  way to know actual format of the array.



 Gilles Simond





More information about the NumPy-Discussion mailing list