[Numpy-discussion] types as functions convert 1 elm arrays to scalars

Hoyt Koepke hoytak at gmail.com
Thu May 1 21:49:52 EDT 2008


To be honest, this doesn't seem justifiable.

Where it got me is interfacing with c-code that expected a 1d array,
and I was calling it with arrays of varying length.  I was using this
to ensure the proper typing; however, when the array was length 1, the
program crashed...

Should I file a bug report?

--Hoyt

On Mon, Apr 28, 2008 at 11:51 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
>
>
> On Tue, Apr 29, 2008 at 12:28 AM, Hoyt Koepke <hoytak at gmail.com> wrote:
> > Hello,
> >
> > I have a quick question that I'm hoping will improve my numpy
> > understanding.  I noticed some behavior when using float64 to convert
> > a matrix type that I didn't expect:
> >
> >
> > In [35]: b1 = array([1.0])
> >
> > In [36]: float64(b1)
> > Out[36]: 1.0
> >
> > In [37]: b2 = array([1.0, 2.0])
> >
> > In [38]: float64(b2)
> > Out[38]: array([ 1.,  2.])
> >
> >
> > I didn't expect calling float64 would convert b1 to a scalar. Seems
> > like an inconsistency.  I assume this is intentional, as someone would
> > have noticed it a long time ago if not, so could someone explain the
> > reasoning behind it?  (or point me to a source that will help?)
> >
>
> It's inconsistent and looks like a bug:
>
> In [4]: float32(array([[[1]]]))
> Out[4]: array([[[ 1.]]], dtype=float32)
>
> In [5]: float64(array([[[1]]]))
> Out[5]: 1.0
>
> Float64 is a bit special because it starts as the python float. Maybe Travis
> can say what the differences are.
>
> Chuck
>
>
>
> _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion at scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>



-- 
+++++++++++++++++++++++++++++++++++
Hoyt Koepke
UBC Department of Computer Science
http://www.cs.ubc.ca/~hoytak/
hoytak at gmail.com
+++++++++++++++++++++++++++++++++++



More information about the NumPy-Discussion mailing list