In python empty sequences are always equivalent to False, and non-empty to
True. You can use this property or:
if len(b) 0:
.
Nadav
-Original Message-
From: numpy-discussion-boun...@scipy.org on behalf of Shailendra
Sent: Fri 02-Apr-10 06:07
To: numpy-discussion@scipy.org
On 4/2/2010 8:29 AM, Nadav Horesh wrote:
In python empty sequences are always equivalent to False, and non-empty to
True.
I think that was why the OP objected to this behavior:
bool(np.array([0]))
False
Alan Isaac
___
On Thu, Apr 1, 2010 at 22:07, Shailendra shailendra.vi...@gmail.com wrote:
Hi All,
Below is some array behaviour which i think is odd
a=arange(10)
a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
b=nonzero(a0)
b
(array([], dtype=int32),)
if not b[0]:
... print 'b[0] is false'
...
b[0] is
On Fri, Apr 2, 2010 at 10:11 AM, Robert Kern robert.k...@gmail.com wrote:
On Thu, Apr 1, 2010 at 22:07, Shailendra shailendra.vi...@gmail.com wrote:
Hi All,
Below is some array behaviour which i think is odd
a=arange(10)
a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
b=nonzero(a0)
b
(array([],
On Thu, Apr 1, 2010 at 10:07 PM, Shailendra shailendra.vi...@gmail.com wrote:
Hi All,
Below is some array behaviour which i think is odd
a=arange(10)
a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
b=nonzero(a0)
b
(array([], dtype=int32),)
if not b[0]:
... print 'b[0] is false'
...
b[0] is
On Fri, Apr 2, 2010 at 08:28, Ryan May rma...@gmail.com wrote:
On Thu, Apr 1, 2010 at 10:07 PM, Shailendra shailendra.vi...@gmail.com
wrote:
Hi All,
Below is some array behaviour which i think is odd
a=arange(10)
a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
b=nonzero(a0)
b
(array([],
Let A be a square matrix of 0's and 1's, and let X be a one dimesional
vector.
The length of X is equal to the number of 1's that A has.
I would like to produce a new matrix B by traversing the matrix A row by row
and:
1- whenever i find a 0, set B in that position to zero.
2- whenever i find a
Thanks everyone for replies/suggestion. It is simple to avoid this
problem. But my point that given the behavior of python this behavior
seems inconsistent. There could other method provided which could
evaluate bool value depending on values stored in the array.
Thanks,
Shailendra
On Fri, Apr
A=[[1,1,0],
... [1,0,0],
... [0,0,1]]
X=[2,9,10,3]
import numpy
A=numpy.asarray(A)
X=numpy.asarray(X)
A
array([[1, 1, 0],
[1, 0, 0],
[0, 0, 1]])
X
array([ 2, 9, 10, 3])
non_zero=numpy.nonzero(A)
non_zero
(array([0, 0, 1, 2]), array([0, 1, 0, 2]))
A[non_zero]
array([1, 1,
On Fri, Apr 2, 2010 at 8:31 AM, Robert Kern robert.k...@gmail.com wrote:
On Fri, Apr 2, 2010 at 08:28, Ryan May rma...@gmail.com wrote:
On Thu, Apr 1, 2010 at 10:07 PM, Shailendra shailendra.vi...@gmail.com
wrote:
Hi All,
Below is some array behaviour which i think is odd
a=arange(10)
a
Hi All,
I have a following model problem. Let i have a array
x
array([[1, 2, 3, 4, 5],
[6, 7, 8, 7, 6],
[1, 2, 3, 4, 5]])
suppose i apply some cond on it.
cond= x5
x[cond]
array([6, 7, 8, 7, 6])
Now, i want to argmax on this
max=argmax(x[cond])
max
2
x[cond][max]
8
Now , I
On Fri, Apr 2, 2010 at 09:31, Shailendra shailendra.vi...@gmail.com wrote:
Hi All,
I have a following model problem. Let i have a array
x
array([[1, 2, 3, 4, 5],
[6, 7, 8, 7, 6],
[1, 2, 3, 4, 5]])
suppose i apply some cond on it.
cond= x5
x[cond]
array([6, 7, 8, 7, 6])
With A and X being arrays:
B=numpy.zeros(A.shape, A.dtype)
B[A0] = X
Armando
Quoting gerardob gberbeg...@gmail.com:
Let A be a square matrix of 0's and 1's, and let X be a one dimesional
vector.
The length of X is equal to the number of 1's that A has.
I would like to produce a new
I forgot to mention that i wanted this to work for general shape. So i
modified it little bit
x = array([[1,2,3,4,5], [6,7,8,7,6], [1,2,3,4,5]])
cond = (x 5)
loc= where(cond)
arg_max=argmax(x[cond])
x[tuple([e[arg_max] for e in loc])]
8
Thanks for your solution.
Shailendra
On Fri, Apr 2,
Hi All,
x=arange(10)
indices=[(1,),(2,)]
x[indices]
Traceback (most recent call last):
File stdin, line 1, in module
IndexError: unsupported iterator index
But following works.
x=x.reshape(5,2)
x
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
On Thu, Apr 1, 2010 at 6:42 PM, David Goldsmith d.l.goldsm...@gmail.comwrote:
np.version.version
'1.4.0'
c = np.polynomial.chebyshev.Chebyshev(1)
c.deriv(1.0)
Chebyshev([ 0.], [-1., 1.])
c.integ(1.0)
Traceback (most recent call last):
File stdin, line 1, in module
File string,
On Thu, Apr 1, 2010 at 7:42 PM, David Goldsmith d.l.goldsm...@gmail.comwrote:
np.version.version
'1.4.0'
c = np.polynomial.chebyshev.Chebyshev(1)
c.deriv(1.0)
Chebyshev([ 0.], [-1., 1.])
c.integ(1.0)
Traceback (most recent call last):
File stdin, line 1, in module
File string,
On Fri, Apr 2, 2010 at 11:27 AM, David Goldsmith d.l.goldsm...@gmail.comwrote:
On Thu, Apr 1, 2010 at 6:42 PM, David Goldsmith
d.l.goldsm...@gmail.comwrote:
np.version.version
'1.4.0'
c = np.polynomial.chebyshev.Chebyshev(1)
c.deriv(1.0)
Chebyshev([ 0.], [-1., 1.])
c.integ(1.0)
On Fri, Apr 2, 2010 at 10:42 AM, Charles R Harris charlesr.har...@gmail.com
wrote:
On Thu, Apr 1, 2010 at 7:42 PM, David Goldsmith
d.l.goldsm...@gmail.comwrote:
np.version.version
'1.4.0'
c = np.polynomial.chebyshev.Chebyshev(1)
c.deriv(1.0)
Chebyshev([ 0.], [-1., 1.])
On Fri, Apr 2, 2010 at 10:46 AM, Charles R Harris charlesr.har...@gmail.com
wrote:
On Fri, Apr 2, 2010 at 11:27 AM, David Goldsmith
d.l.goldsm...@gmail.comwrote:
Also:
c.deriv(0)
Chebyshev([ 1.], [-1., 1.])
c.integ(0)
Traceback (most recent call last):
File stdin, line 1, in
Shailendra shailendra.vikas at gmail.com writes:
I forgot to mention that i wanted this to work for general shape. So i
modified it little bit
x = array([[1,2,3,4,5], [6,7,8,7,6], [1,2,3,4,5]])
cond = (x 5)
loc= where(cond)
arg_max=argmax(x[cond])
x[tuple([e[arg_max] for e in
I am writing a setup.py file for a package that will use cython with
numpy integration. This of course requires the numpy header files,
which I am including by using numpy.get_includes in the setup.py file
below. The problem is for users that have not installed numpy before
installing this
On Fri, Apr 2, 2010 at 13:03, Erik Tollerud erik.tolle...@gmail.com wrote:
I am writing a setup.py file for a package that will use cython with
numpy integration. This of course requires the numpy header files,
which I am including by using numpy.get_includes in the setup.py file
below. The
I get AttributeError: 'NoneType' object has no attribute 'accumulate' for
the call
vecfun.ufunc.accumulate(np.array([0, 1, 2, 3]))
It works fine if I make a dummy call to vecfun before! Any idea for
this behavior?
Thanks
Vishal Rana
On Mon, Mar 29, 2010 at 4:07 AM, Nadav Horesh
Well, this is just a toy problem. argmax represent a method which will
give me a index in x[cond] . And for the case of multiple value my
requirement is fine with getting any max index.
Thanks,
Shailendra
On Fri, Apr 2, 2010 at 3:00 PM, eat e.antero.ta...@gmail.com wrote:
Shailendra
Shailendra shailendra.vikas at gmail.com writes:
Well, this is just a toy problem. argmax represent a method which will
give me a index in x[cond] . And for the case of multiple value my
requirement is fine with getting any max index.
OK. My concern seems to be needless then.
BTW, does
Hi,
I know its easy, but I am not just getting it...
How do I get last element on axis=1 for:
a = array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
Expected: array([4, 9, 14, 19, 24])
Thanks
Vishal
Vishal Rana wrote:
Hi,
I know its easy, but I am not just getting it...
How do I get last element on axis=1 for:
a = array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
Expected: array([4, 9,
Thanks Warren!
On Fri, Apr 2, 2010 at 2:46 PM, Warren Weckesser
warren.weckes...@enthought.com wrote:
Vishal Rana wrote:
Hi,
I know its easy, but I am not just getting it...
How do I get last element on axis=1 for:
a = array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
On Fri, Apr 2, 2010 at 3:03 PM, Erik Tollerud erik.tolle...@gmail.comwrote:
you could try something like this (untested):
if __name__ == '__main__':
try:
import numpy
except ImportError:
import subprocess
subprocess.check_call(['easy_install', 'numpy']) # will
On Fri, Apr 2, 2010 at 11:45 PM, Chris Colbert sccolb...@gmail.com wrote:
On Fri, Apr 2, 2010 at 3:03 PM, Erik Tollerud erik.tolle...@gmail.com
wrote:
you could try something like this (untested):
if __name__ == '__main__':
try:
import numpy
except ImportError:
31 matches
Mail list logo