types as functions convert 1 elm arrays to scalars
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?) Thanks! Hoyt  +++++++++++++++++++++++++++++++++++ Hoyt Koepke UBC Department of Computer Science http://www.cs.ubc.ca/~hoytak/ hoytak@gmail.com +++++++++++++++++++++++++++++++++++
On Tue, Apr 29, 2008 at 12:28 AM, Hoyt Koepke <hoytak@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
To be honest, this doesn't seem justifiable. Where it got me is interfacing with ccode 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@gmail.com> wrote:
On Tue, Apr 29, 2008 at 12:28 AM, Hoyt Koepke <hoytak@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
_______________________________________________ Numpydiscussion mailing list Numpydiscussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpydiscussion
 +++++++++++++++++++++++++++++++++++ Hoyt Koepke UBC Department of Computer Science http://www.cs.ubc.ca/~hoytak/ hoytak@gmail.com +++++++++++++++++++++++++++++++++++
On Thu, May 1, 2008 at 7:49 PM, Hoyt Koepke <hoytak@gmail.com> wrote:
To be honest, this doesn't seem justifiable.
Where it got me is interfacing with ccode 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?
I already did, it's ticket #764. Chuck
Okay, thanks! I didn't check. Hoyt On Thu, May 1, 2008 at 7:00 PM, Charles R Harris <charlesr.harris@gmail.com> wrote:
On Thu, May 1, 2008 at 7:49 PM, Hoyt Koepke <hoytak@gmail.com> wrote:
To be honest, this doesn't seem justifiable.
Where it got me is interfacing with ccode 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?
I already did, it's ticket #764.
Chuck
_______________________________________________ Numpydiscussion mailing list Numpydiscussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpydiscussion
 +++++++++++++++++++++++++++++++++++ Hoyt Koepke UBC Department of Computer Science http://www.cs.ubc.ca/~hoytak/ hoytak@gmail.com +++++++++++++++++++++++++++++++++++
participants (2)

Charles R Harris

Hoyt Koepke