

Hi,
Is it bug if different NumPy types have different attributes?
Based on prior discussion, 'complex', 'float' and 'int' are Python types
and others are NumPy types. Consequently 'complex', 'float' and 'int'
do not inherit from NumPy. However, an element from array created using
dtype=numpy.float has the numpy.float64 type. So this is really a
documentation issue than an implementation issue.
Also different NumPy types have different attributes, for example,
'float64' contains attributes (eg __coerce__) that are not present in
'float32' and 'float128' (these two have the same attributes). This can
cause attribute errors in somewhat contrived examples that probably are
unlikely to appear in practice because of the casting involved in array
creation.
The 'uint' types all seem to have the same attributes so do not have
these issues.
import numpy
len(dir(float)) # 47
len(dir(numpy.float)) # 47
len(dir(numpy.float32)) # 131
len(dir(numpy.float64)) # 135
len(dir(numpy.float128)) # 131
len(dir(int)) # 54
len(dir(numpy.int)) # 54
len(dir(numpy.int0)) # 135
len(dir(numpy.int16)) # 132
len(dir(numpy.int32)) # 132
len(dir(numpy.int64)) # 135
len(dir(numpy.int8)) # 132
print (numpy.float64(1234).size) # 1
print (numpy.float(1234).size)
''' prints error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute 'size'
'''
Regards
Bruce
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


Bruce Southey wrote:
> Hi,
> Is it bug if different NumPy types have different attributes?
>
I don't think so, other than perhaps we should not have the Python types
in the numpy namespace.
numpy.float is just __builtin__.float which is a Python type not a
NumPy datatype object.
numpy.float64 inherits from numpy.float however.
Travis
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


On Thu, May 22, 2008 at 10:24 AM, Travis E. Oliphant
< [hidden email]> wrote:
> Bruce Southey wrote:
>> Hi,
>> Is it bug if different NumPy types have different attributes?
>>
> I don't think so, other than perhaps we should not have the Python types
> in the numpy namespace.
>
> numpy.float is just __builtin__.float which is a Python type not a
> NumPy datatype object.
>
> numpy.float64 inherits from numpy.float however.
And I believe this is the cause of the difference between the
attributes of numpy.float32/numpy.float128 and numpy.float64. Same
deal with int0 and int64 on your presumably 64bit platform.

Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 Umberto Eco
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


Hi,
Thanks very much for the confirmation.
Bruce
On Thu, May 22, 2008 at 2:09 PM, Robert Kern < [hidden email]> wrote:
> On Thu, May 22, 2008 at 10:24 AM, Travis E. Oliphant
> < [hidden email]> wrote:
>> Bruce Southey wrote:
>>> Hi,
>>> Is it bug if different NumPy types have different attributes?
>>>
>> I don't think so, other than perhaps we should not have the Python types
>> in the numpy namespace.
>>
>> numpy.float is just __builtin__.float which is a Python type not a
>> NumPy datatype object.
>>
>> numpy.float64 inherits from numpy.float however.
>
> And I believe this is the cause of the difference between the
> attributes of numpy.float32/numpy.float128 and numpy.float64. Same
> deal with int0 and int64 on your presumably 64bit platform.
>
> 
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>  Umberto Eco
> _______________________________________________
> Numpydiscussion mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/numpydiscussion>
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


On Thu, May 22, 2008 at 1:32 PM, Bruce Southey < [hidden email]> wrote:
Hi,
Thanks very much for the confirmation.
Bruce
On Thu, May 22, 2008 at 2:09 PM, Robert Kern <[hidden email]> wrote:
> On Thu, May 22, 2008 at 10:24 AM, Travis E. Oliphant
> <[hidden email]> wrote:
>> Bruce Southey wrote:
>>> Hi,
>>> Is it bug if different NumPy types have different attributes?
>>>
>> I don't think so, other than perhaps we should not have the Python types
>> in the numpy namespace.
>>
>> numpy.float is just __builtin__.float which is a Python type not a
>> NumPy datatype object.
>>
>> numpy.float64 inherits from numpy.float however.
>
> And I believe this is the cause of the difference between the
> attributes of numpy.float32/numpy.float128 and numpy.float64. Same
> deal with int0 and int64 on your presumably 64bit platform.
> It also leads to various inconsistencies:
In [1]: float32(array([[1]])) Out[1]: array([[ 1.]], dtype=float32)
In [2]: float64(array([[1]])) Out[2]: 1.0
Chuck
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


On Thu, May 22, 2008 at 2:46 PM, Charles R Harris
< [hidden email]> wrote:
> It also leads to various inconsistencies:
>
> In [1]: float32(array([[1]]))
> Out[1]: array([[ 1.]], dtype=float32)
>
> In [2]: float64(array([[1]]))
> Out[2]: 1.0
Okay, so don't do that. Always use x.astype(dtype) or asarray(x, dtype).

Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 Umberto Eco
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


On Thu, May 22, 2008 at 2:59 PM, Robert Kern < [hidden email]> wrote:
> On Thu, May 22, 2008 at 2:46 PM, Charles R Harris
> < [hidden email]> wrote:
>> It also leads to various inconsistencies:
>>
>> In [1]: float32(array([[1]]))
>> Out[1]: array([[ 1.]], dtype=float32)
>>
>> In [2]: float64(array([[1]]))
>> Out[2]: 1.0
>
> Okay, so don't do that. Always use x.astype(dtype) or asarray(x, dtype).
>
> 
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>  Umberto Eco
> _______________________________________________
> Numpydiscussion mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/numpydiscussion>
So, should these return an error if the argument is an ndarray object,
a list or similar?
Otherwise, int, float and string type of arguments would be okay under
the assumption that people would like variable precision scalars.
Bruce
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


On Thu, May 22, 2008 at 4:25 PM, Bruce Southey < [hidden email]> wrote:
> On Thu, May 22, 2008 at 2:59 PM, Robert Kern < [hidden email]> wrote:
>> On Thu, May 22, 2008 at 2:46 PM, Charles R Harris
>> < [hidden email]> wrote:
>>> It also leads to various inconsistencies:
>>>
>>> In [1]: float32(array([[1]]))
>>> Out[1]: array([[ 1.]], dtype=float32)
>>>
>>> In [2]: float64(array([[1]]))
>>> Out[2]: 1.0
>>
>> Okay, so don't do that. Always use x.astype(dtype) or asarray(x, dtype).
>
> So, should these return an error if the argument is an ndarray object,
> a list or similar?
I think it was originally put in as a feature, but given the
inconsistency and the longstanding alternatives, I would deprecate
its use for converting array dtypes. But that's just my opinion.
> Otherwise, int, float and string type of arguments would be okay under
> the assumption that people would like variable precision scalars.
Yes.

Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 Umberto Eco
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


On Thu, May 22, 2008 at 5:07 PM, Robert Kern < [hidden email]> wrote:
On Thu, May 22, 2008 at 4:25 PM, Bruce Southey < [hidden email]> wrote:
> On Thu, May 22, 2008 at 2:59 PM, Robert Kern < [hidden email]> wrote:
>> On Thu, May 22, 2008 at 2:46 PM, Charles R Harris
>> < [hidden email]> wrote:
>>> It also leads to various inconsistencies:
>>>
>>> In [1]: float32(array([[1]]))
>>> Out[1]: array([[ 1.]], dtype=float32)
>>>
>>> In [2]: float64(array([[1]]))
>>> Out[2]: 1.0
>>
>> Okay, so don't do that. Always use x.astype(dtype) or asarray(x, dtype).
>
> So, should these return an error if the argument is an ndarray object,
> a list or similar?
I think it was originally put in as a feature, but given the
inconsistency and the longstanding alternatives, I would deprecate
its use for converting array dtypes. But that's just my opinion.
I agree. Having too many ways to do things just makes for headaches. Should we schedule in a deprecation for anything other than scalars and strings.
Chuck
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion


Charles R Harris wrote:
>
>
> On Thu, May 22, 2008 at 5:07 PM, Robert Kern < [hidden email]
> <mailto: [hidden email]>> wrote:
>
> On Thu, May 22, 2008 at 4:25 PM, Bruce Southey < [hidden email]
> <mailto: [hidden email]>> wrote:
> > On Thu, May 22, 2008 at 2:59 PM, Robert Kern
> < [hidden email] <mailto: [hidden email]>> wrote:
> >> On Thu, May 22, 2008 at 2:46 PM, Charles R Harris
> >> < [hidden email] <mailto: [hidden email]>>
> wrote:
> >>> It also leads to various inconsistencies:
> >>>
> >>> In [1]: float32(array([[1]]))
> >>> Out[1]: array([[ 1.]], dtype=float32)
> >>>
> >>> In [2]: float64(array([[1]]))
> >>> Out[2]: 1.0
> >>
> >> Okay, so don't do that. Always use x.astype(dtype) or
> asarray(x, dtype).
> >
> > So, should these return an error if the argument is an ndarray
> object,
> > a list or similar?
>
> I think it was originally put in as a feature, but given the
> inconsistency and the longstanding alternatives, I would deprecate
> its use for converting array dtypes. But that's just my opinion.
>
>
> I agree. Having too many ways to do things just makes for headaches.
> Should we schedule in a deprecation for anything other than scalars
> and strings.
I don't have a strong opinion either way.
Travis
_______________________________________________
Numpydiscussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpydiscussion

