Re: [Numpy-discussion] Memory leak found in ndarray (I think)?

2010-07-12 Thread Nathaniel Peterson
This memory leak may be related: http://projects.scipy.org/numpy/ticket/1542
It shows what appears to be a memory leak when calling astype('float')
on an array of dtype 'object'.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Memory leak found in ndarray (I think)?

2010-07-12 Thread Nathaniel Peterson
Wes McKinney wesmck...@gmail.com writes:

 Did you mean to post a different link? That's the ticket I just created :)

How silly of me! I meant http://projects.scipy.org/numpy/ticket/1427
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Possible bug in indexed masked arrays

2010-04-05 Thread Nathaniel Peterson
Pierre, Thank you for the wonderful explanation.
I get it! np.alltrue(idx.data == idx2.data) is False. 

PS. Thank you for closing ticket #1447; sorry for the trouble.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Possible bug in indexed masked arrays

2010-04-01 Thread Nathaniel Peterson

Is this behavior of masked arrays intended, or is it a bug? 

This part works as I would expected:

import numpy as np
a=np.ma.fix_invalid(np.array([np.nan,-1,0,1]))
b=np.ma.fix_invalid(np.array([np.nan,-1,0,1]))
idx=(a==b)
print(a[idx][3])
# 1.0

Note that a[idx] has shape (4,).
But if I change the first element of b from np.nan to 2.0 then
a[idx2] has shape (3,) despite np.alltrue(idx==idx2) being True:

c=np.ma.fix_invalid(np.array([2.0,-1,0,1]))
idx2=(a==c)
assert(np.alltrue(idx==idx2))
a[idx2][3]

# Traceback (most recent call last):
#   File /home/np/test.py, line 12, in module
# a[idx2][3]
#   File /usr/lib/python2.6/dist-packages/numpy/ma/core.py, line 2578, in 
__getitem__
# dout = ndarray.__getitem__(ndarray.view(self, ndarray), indx)
# IndexError: index out of bounds

I looked at repr(idx) and repr(idx2) and they appear to have equal values in 
all respects.
If that is true, why should a[idx] be different than a[idx2]?
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Can numpy catch this error for me?

2009-04-07 Thread Nathaniel Peterson
import numpy as np
import operator
np.seterr(all='raise')
a=np.arange(1)+1
print(a.dtype)
# int32
for num in range(1,17):
a=np.arange(num)+1
b=np.multiply.reduce(a)
print('%s! = %s'%(num,b))
# c=reduce(operator.mul,range(1,num+1))
# assert(b==c)

The code above outputs

int32
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 1932053504
14! = 1278945280
15! = 2004310016
16! = 2004189184

The results for 14! and above are wrong due to overflow of the int32 data
type.
Is there a way to setup numpy so it will raise an error when this occurs?
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Can numpy catch this error for me?

2009-04-07 Thread Nathaniel Peterson
Thanks for the quick response.
In http://www.scipy.org/Cookbook/Indexing
I see

 a = C[1,2,3]
 a
23
 type(a)
type 'numpy.int32'
 type(int(a))
type 'int'
 a**a
Warning: overflow encountered in long_scalars
-1276351769
 int(a)**int(a)
20880467999847912034355032910567L

This shows numpy can catch an overflow generated by a**a.
Why is it that numpy can catch this overflow,
but can not catch one generated by np.multiply.reduce?
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Can numpy catch this error for me?

2009-04-07 Thread Nathaniel Peterson
Okay; thank you very much for the explanation.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion