Re: [Numpy-discussion] loadtxt and N/A

2008-07-13 Thread Lorenzo Bolla
you can use the 'converters' keyword in numpy.loadtxt.
first define a function to convert a string in a float, that can handle
your 'N/A' entries:

def converter(x):
if x == 'N/A':
return numpy.nan
else:
return float(x)

then use:

>>> numpy.loadtxt('test.dat', converters={1:converter,2:converter})
array([[  1.,   2.,  NaN,   4.],
   [  1.,  NaN,   3.,   4.]])

where the file test.dat I used looks like this:
1 2 N/A 4
1 N/A 3 4

hth,
L.

On Sun, Jul 13, 2008 at 09:50:24AM -0400, Bryan Fodness wrote:
> I am using loadtxt and I have missing values that are show up as N/A.
> 
> I get a,
> 
> ValueError: invalid literal for float(): N/A
> 
> Is there a way to ignore these?

> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] loadtxt and usecols

2008-07-12 Thread Lorenzo Bolla
why not using:
data = loadtxt('18B180.dat', skiprows = 1, usecols = xrange(1,46))

obviously, you need to know how many columns you have.
hth,
L.

On Sat, Jul 12, 2008 at 10:07:06AM -0400, Bryan Fodness wrote:
> i would like to load my data without knowing the length, i have explicitly
> stated the rows
> 
> data = loadtxt('18B180.dat', skiprows = 1, usecols =
> 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45))
> and would like to use something like,
> 
> data = loadtxt('18B180.dat', skiprows = 1, usecols = (1,:))
> 
> the first column is the only that i do not need.
> 
> -- 
> "The game of science can accurately be described as a never-ending insult to
> human intelligence." - João Magueijo
> 
> "Any intelligent fool can make things bigger, more complex, and more
> violent. It takes a touch of genius - and a lot of courage - to move in the
> opposite direction. " -Albert Einstein

> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Combination of element-wise and matrix multiplication

2008-07-04 Thread lorenzo bolla
If a and b are 2d arrays, you can use numpy.dot:

In [36]: a
Out[36]:
array([[1, 2],
   [3, 4]])
In [37]: b
Out[37]:
array([[5, 6],
   [7, 8]])
In [38]: numpy.dot(a,b)
Out[38]:
array([[19, 22],
   [43, 50]])

If a and b are 3d arrays of shape 2x2xN, you can use something like that:
In [52]: a = numpy.arange(16).reshape(2,2,4)
In [53]: b = numpy.arange(16,32).reshape(2,2,4)
In [54]: c = numpy.array([numpy.dot(a[...,i],b[...,i]) for i in
xrange(a.shape[-1])])
In [55]: c.shape
Out[55]: (4, 2, 2)

Here c has shape (4,2,2) instead (2,2,4), but you got the idea!

hth,
L.


On Thu, Jul 3, 2008 at 9:53 PM, Jonno <[EMAIL PROTECTED]> wrote:

> I have two 2d arrays a & b for example:
> a=array([c,d],[e,f])
> b=array([g,h],[i,j])
> Each of the elements of a & b are actually 1d arrays of length N so I
> guess technically a & b have shape (2,2,N).
> However I want to matrix multiply a & b to create a 2d array x, where
> the elements of x are created with element-wise math as so:
> x[0,0] = c*g+d*i
> x[0,1] = c*h+d*j
> x[1,0] = e*g+f*i
> x[1,1] = e*h+f*j
>
> What is the simplest way to do this? I ended up doing the matrix
> multiplication of a & b manually as above but this doesn't scale very
> nicely if a & b become larger in size.
>
> Cheers,
>
> Jonno.
>
> --
> "If a theory can't produce hypotheses, can't be tested, can't be
> disproven, and can't make predictions, then it's not a theory and
> certainly not science." by spisska  on Slashdot, Monday April 21, 2008
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
"Whereof one cannot speak, thereof one must be silent." -- Ludwig
Wittgenstein
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] bvp on 64 bits machine

2008-06-04 Thread lorenzo bolla
Hello all.

I'm not sure that this is the correct mailing list to post to: please excuse
me if it's not.

I've been using bvp (http://www.elisanet.fi/ptvirtan/software/bvp/index.html)
by Pauli Virtanen happily on 32 bits machines.
When I used it on 64 bits machines I found a bug that I think I've solved
with the following patch:

=

$ diff colnew.py.old colnew.py
347c347
< ispace = _N.empty([nispace], _N.int_)
---
> ispace = _N.empty([nispace], _N.int32)
402c402
< ], _N.int_)
---
> ], _N.int32)

=

The problem is cause by the fact that _N.int_ is different for 32 and 64
bits machines. Forcing it to be an _N.int32 did the trick.
Pauli, would you like to commit it to your source distribution?

Regards,
Lorenzo.

-- 
"Whereof one cannot speak, thereof one must be silent." -- Ludwig
Wittgenstein
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] insert 1D to a 2D array and change it to 3D

2008-04-25 Thread lorenzo bolla
why not using something like numpy.repeat?

In [18]: B = numpy.random.rand(4,3)
In [19]: A = numpy.repeat(B[:,:,numpy.newaxis],2,axis=2)
In [20]: B.shape
Out[20]: (4, 3)
In [21]: A.shape
Out[21]: (4, 3, 2)
In [22]: numpy.all(A[:,:,0] == A[:,:,1])
Out[22]: True

hth,
L.


On Fri, Apr 25, 2008 at 12:09 PM, Matthieu Brucher <
[EMAIL PROTECTED]> wrote:

>
>
> 2008/4/25, tournesol <[EMAIL PROTECTED]>:
>>
>> Hi All.
>>
>>
>> I just want to conver Fortran 77 source to
>> Python.
>>
>> Here is my F77 source.
>>
>> DIMENSION A(25,60,13),B(25,60,13)
>>
>> open(15,file='data.dat')
>> DO 60 K=1,2
>> READ(15,1602) ((B(I,J),J=1,60),I=1,25)
>> 60 CONTINUE
>>   1602 FORMAT(15I4)
>>
>> DO 63 K=1,10
>> DO 62 I=1,25
>> DO 62 J=1,60
>> A(I,J,K)=B(I,J)
>> 62 CONTINUE
>> 63 CONTINUE
>> END
>>
>> Q1: Fortran-contiguous is ARRAY(row,colum,depth).
>>  How about the Python-contiguous ? array(depth,row,colum) ?
>
>
>
> Default is C-contiguous, but you can you Fortran contiguous arrays.
>
>
> Q2: How can I insert 1D to a 2D array and make it to
>>  3D array. ex:) B:25x60 ==> A: 10X25X60
>>
>
> I don't understand what you want to do, but broadcasting allows copying
> several instances of an array into another one.
>
> Matthieu
> --
> French PhD student
> Website : http://matthieu-brucher.developpez.com/
> Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
> LinkedIn : http://www.linkedin.com/in/matthieubrucher
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Fromfunction generalization

2008-04-22 Thread lorenzo bolla
what about using lambda functions?

M=fromfunction(lambda i,j:f(i,j,5),(1000,1000))
P=fromfunction(lambda i,j:f(i,j,7),(1000,1000))

L.

On Tue, Apr 22, 2008 at 8:42 PM, Gnata Xavier <[EMAIL PROTECTED]>
wrote:

> Hi,
>
> fromfunction is fine but I have like to be able to create 2Darrays using
> a function of i,j but also of one (or more) parameters.
> Something like that :
>
> def f(i,j,a):
>return (i+j)*a #replace that by another non trivial computation
>
> M=fromfunction(f( hum well something like i,j,a),(1000,1000))
>
> this only way I know is to use global :
>
> a=5
>
> def f(i,j):
>global a
>return (i+j)*a
>
> M=fromfunction(f,(1000,1000))
> a=7
> P=fromfunction(f,(1000,1000))
>
> but it is quite ugly :(
>
> Is there a clean and *fast* way to do that ?
>
> Xavier
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] different behaviour in asfarray(None)

2008-04-22 Thread lorenzo bolla
I noticed a change in the behaviour of numpy.asfarray between numpy version
1.0.5 and 1.1.0:

1.0.5


In [3]: numpy.asfarray(None)
Out[3]: array(nan)
In [4]: numpy.__version__
Out[4]: '1.0.5.dev4455'

1.1.0


In [16]: numpy.asfarray(None)
---
 Traceback (most recent call last)

c:\Documents and Settings\bollalo001\My
Documents\archive\python\openopt\ in ()

c:\Python25\Lib\site-packages\numpy\lib\type_check.py in asfarray(a, dtype)
 47 if not issubclass(dtype, _nx.inexact):
 48 dtype = _nx.float_
---> 49 return asarray(a,dtype=dtype)
 50
 51 def real(val):

c:\Python25\Lib\site-packages\numpy\core\numeric.py in asarray(a, dtype,
order)
133 are converted to base class ndarray.
134 """
--> 135 return array(a, dtype, copy=False, order=order)
136
137 def asanyarray(a, dtype=None, order=None):

: float() argument must be a string or a number

In [17]: numpy.__version__
Out[17]: '1.1.0.dev5061'


Is this intended? why?

L.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Numpy 1.1.0 and matplotlib 0.90.1

2008-04-22 Thread lorenzo bolla
Hello,

the latest svn numpy version 1.1.0.dev5061 does not work with matplotlib
0.90.1 (version shipped with enthought distribution), unless a change in
Python25/Lib/site-packages/matplotlib-0.90.1.0003-py2.5-win32.egg/matplotlib/numerix/ma/__init__.py
is done:

$ diff __init__.py.orig __init__.py
12c12
< from numpy.core.ma import *
---
> from numpy.ma import *

Maybe this should be forwarded to the pylab mailing list, but I'm not
subscribed there...

L.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] linalg.eigh() newbie doubt

2008-03-31 Thread lorenzo bolla
from numpy.eigh?:

:Returns:

w : 1-d double array
The eigenvalues. The eigenvalues are not necessarily ordered.

v : 2-d double or complex double array, depending on input array
type
The normalized eigenvector corresponding to the eigenvalue w[i]
is
the column v[:,i].

so, yes, the eigvec coresponding to the eigval w[i] is v[:,i].
L.


On Mon, Mar 31, 2008 at 4:43 PM, gordon <[EMAIL PROTECTED]> wrote:

> hello
> i was trying the linalg.eigh()
> when i apply eigh() on a covariance matrix (an ndarray of shape 6x6  i
> get evals,evectors
> suppose i get it like
>
> evals=   array([2.2, 5.5, 4.4, 1.7, 7.7, 6.3])
> evectors=array([[3.,5. ,1. ,6. ,2. ,4. ],
>[2.,1.,5.,7.,5.,3.],
>[8.,9.,6.,5.,4.,3.],
>[2.,1.,3.,4.,5.,9.],
>[0.1,3.,2.,4.,5.,1.],
>[6.,5.,7.,4.,2.,8.]
>])
> which is the array that corresponds to eigenvalue 2.2 of evals?
> is it the first column of evectors? or is it the first row?
>
> if i were to sort the evectors based on the eigenvalue ,i guess the
> most significant eigenvector should correspond to the value of
> 7.7 ,then am i supposed to consider the 5th column of evectors as the
> most significant eigenvector?
> please someone help me clear this confusion
> thanks
> gordon
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] greedy loadtxt

2008-03-27 Thread lorenzo bolla
Thank you all.
The problem with fromfile() is that it doesn't know anything about ndarrays.
If my file is a table of ncols and nrows, fromfile() will give me a 1darray
with nrows*ncols elements, while loadtxt() will give me a 2dmatrix nrows x
ncols. In other words, I loose the "shape" of the table.
L.

On Thu, Mar 27, 2008 at 7:59 PM, Christopher Barker <[EMAIL PROTECTED]>
wrote:

> Alan G Isaac wrote:
> > I believe Robert fixed this;
> > update from the SVN repository.
>
> lorenzo bolla wrote:
> > Should I use numpy.fromfile, instead?
>
> You can also do that. If fromfile() supports your data format, it will
> be much faster.
>
> -Chris
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R(206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115   (206) 526-6317   main reception
>
> [EMAIL PROTECTED]
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] greedy loadtxt

2008-03-27 Thread lorenzo bolla
Hi all!

I realized that numpy.loadtxt do not read the last character of an input
file. This is annoying if the input file do not end with a newline.
For example:

data.txt
---
1 2 3

In [33]: numpy.loadtxt('data.txt')
Out[33]: array([ 1.,  2.])


While:

data.txt
---
1 2 3


In [33]: numpy.loadtxt('data.txt')
Out[33]: array([ 1.,  2., 3.])


Should I use numpy.fromfile, instead?
L.

-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Quikest way to create a diagonal matrix ?

2008-03-26 Thread lorenzo bolla
I like obfuscating things! Maybe I should switch to perl :-)
you can use a one-liner like this:

scipy.linalg.triu(z) + scipy.linalg.triu(z,k=1).T

my %timeit gives roughly the same execution speed as your f(z):

In [79]: %timeit f(z)
1 loops, best of 3: 79.3 us per loop

In [80]: %timeit h(z)
1 loops, best of 3: 76.8 us per loop

L.

On Wed, Mar 26, 2008 at 4:21 PM, Joris De Ridder <
[EMAIL PROTECTED]> wrote:

>
> On 26 Mar 2008, at 15:36, lorenzo bolla wrote:
>
> > numpy.tri
> >
> > In [31]: T = numpy.tri(m)
> >
> > In [32]: z.T * T + z * T.T
> > Out[32]:
> > array([[  0.,   1.,   2.,   3.,   4.],
> >[  1.,  12.,   7.,   8.,   9.],
> >[  2.,   7.,  24.,  13.,  14.],
> >[  3.,   8.,  13.,  36.,  19.],
> >[  4.,   9.,  14.,  19.,  48.]])
>
>
> You still have to subtract the diagonal:
>
> def f(z):
> A = tri(z.shape[0], dtype = z.dtype)
> X = z.T * A + z * A.T
> X[range(A.shape[0]),range(A.shape[0])] -= z.diagonal()
> return X
>
>
> The suggestion of Alexandre seems to be about 4 times as fast, though.
>
> But I love the way you obfuscate things by having "T" for both the tri-
> matrix as the transpose method. :-)
> It get's even better with numpy matrices. Next year, my students will
> see something like
> I.H-T.H*T.I+I.I*H.I+T.T*H.H-H.I
> Refreshing! ;-)
>
> Cheers,
> Joris
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
> ___________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Quikest way to create a diagonal matrix ?

2008-03-26 Thread lorenzo bolla
numpy.tri

In [31]: T = numpy.tri(m)

In [32]: z.T * T + z * T.T
Out[32]:
array([[  0.,   1.,   2.,   3.,   4.],
   [  1.,  12.,   7.,   8.,   9.],
   [  2.,   7.,  24.,  13.,  14.],
   [  3.,   8.,  13.,  36.,  19.],
   [  4.,   9.,  14.,  19.,  48.]])

hth,
L.

On Wed, Mar 26, 2008 at 2:48 PM, Pierre GM <[EMAIL PROTECTED]> wrote:

> All,
> What's the quickest way to create a diagonal matrix ? I already have the
> elements above the main diagonal. Of course, I could use loops:
> >>>m=5
> >>>z = numpy.arange(m*m).reshape(m,m)
> >>>for k in range(m):
> >>>for j in range(k+1,m):
> >>>z[j,k] = z[k,j]
> But I was looking for something more efficient.
> Thanks a lot in advance !
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread lorenzo bolla
use the "axis" argument in sum.
L.

On Tue, Mar 18, 2008 at 4:27 PM, Chris Withers <[EMAIL PROTECTED]>
wrote:

> Keith Goodman wrote:
> >>> sum(x)
> >
> > matrix([[ 1.15063313],
> > [ 0.8841396 ],
> > [ 1.7370669 ]])
>
> When these are arrays, I just get a single number sum back...
>
> Chris
>
> --
> Simplistix - Content Management, Zope & Python Consulting
>- http://www.simplistix.co.uk
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] arccosh for complex numbers, goofy choice of branch

2008-03-17 Thread lorenzo bolla
Matlab is consistent, I'm afraid:

>> acosh(1.5)
ans =
0.9624
>> acosh(1.5 + 0j)
ans =
0.9624

L.


On Mon, Mar 17, 2008 at 9:40 AM, Charles R Harris <[EMAIL PROTECTED]>
wrote:

> OK,
>
> Which branch do we want to use. As it currently is in numpy and
> scipy.special
>
> arccosh(1.5) =  0.96242365011920694
> arccosh(1.5+0j) =  -0.96242365011920705 + 0.0j
>
> This is consistent with gsl, but inconsistent with Mathematica, NAG,
> Maple, and probably all sensible implementations which use the generally
> accepted principal value. I've left this inconsistency raising an error in
> the ufunc tests until we make a decision. It might be nice to know what
> FORTRAN and MatLab do with this.
>
> Chuck
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Read array from file

2008-03-14 Thread lorenzo bolla
what about numpy.loadtxt?

In [9]: numpy.loadtxt('test.dat', skiprows=5)
Out[9]:
array([[ 15.44261,  12.05814,  54.43124],
   [ 15.54899,  12.00075,  53.85503],
   [ 15.95802,  11.92959,  53.88939],
   [ 15.84085,  12.00235,  54.43274],
   [ 15.53889,  11.16645,  54.51649],
   [ 15.57673,  11.10806,  53.96009],
   [ 16.10059,  11.06809,  53.87672],
   [ 16.04238,  11.11615,  54.47454],
   [ 15.78142,  11.82206,  53.33932],
   [ 16.13055,  11.75515,  53.3731 ]])

hth,
L.

On Fri, Mar 14, 2008 at 11:12 AM, Dimitrios Kiousis <[EMAIL PROTECTED]>
wrote:

> Hello python users,
>
> I have an input file consisting of string-lines and float-lines. This is
> how it looks:
>
> # vtk DataFile Version 3.0
> VTK file exported from FEAP
> ASCII
> DATASET UNSTRUCTURED_GRID
> POINTS6935  FLOAT
>   15.44261   12.05814   54.43124
>   15.54899   12.00075   53.85503
>   15.95802   11.92959   53.88939
>   15.84085   12.00235   54.43274
>   15.53889   11.16645   54.51649
>   15.57673   11.10806   53.96009
>   16.10059   11.06809   53.87672
>   16.04238   11.11615   54.47454
>   15.78142   11.82206   53.33932
>   16.13055   11.75515   53.37313
>   .
>
> I want to read the first 5 string lines, and then store the float data
> (coordinates) into an array.
> It took me some time to figure this out but this is the script with which
> I came out:
>
>  # Read and write the first information lines
> for i in range(0,5):
>   Fdif.write( Fpst.readline() )
>
> # Read and write coordinates
> # --
>
> # Initialization
> coords = zeros( (nnod,3), float )
>
> for i in range(0,nnod):
>   # Read line
>   x = Fref.readline() # Read lines
>   x = x.split()   # Split line to strings
>   x = map ( float,x ) # Convert string elements to floats
>   x = array ( x ) # Make an array
>   for j in range (0,3):
> coords[i,j] = x[j]
>
> It seems quite complicated to me, but I haven't figure any nicer way.
> Could you tell me if what I am doing looks reasonanble or if there are any
> other solutions?
> Do I really need to initiallize coords?
>
> Thanks in advance,
> Dimitrios
>
> _______
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
oops. it fails also on an SGI Altix with Suse Linux on it:
Linux pico 2.6.16.27-0.9-default #1 SMP Tue Feb 13 09:35:18 UTC 2007 ia64
ia64 ia64 GNU/Linux


In [33]: A = numpy.array(['a','aa','b'])
In [34]: B = numpy.array(['d','e'])
In [35]: A.searchsorted(B)
Out[35]: array([3, 0])
In [36]: numpy.__version__
Out[36]: '1.0.5.dev4567'


The problem seems to be in the different dtypes of A and B.
Using the same dtype '|S2' it works fine.

 
In [38]: A = numpy.array(['a','aa','b'])

In [39]: A.dtype
Out[39]:
dtype('|S2')

In [40]: B = numpy.array(['d','e'])
In [41]: A.searchsorted(B)
Out[41]: array([3, 0])
In [42]: B = numpy.array(['d','e'], dtype='|S2')
In [43]: A.searchsorted(B)
Out[43]: array([3, 3])
 

L.



On 1/31/08, Matthieu Brucher <[EMAIL PROTECTED]> wrote:
>
> No problem for me (also a svn version) :
>
> Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
> [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
>
> >>> import numpy
> >>> A = numpy.array(['a','aa','b'])
> >>> B = numpy.array(['d','e'])
> >>> A.searchsorted(B)
> array([3, 3])
>
> Matthieu
>
> 2008/1/31, lorenzo bolla <[EMAIL PROTECTED]>:
> >
> > I use a dev version (1.0.5.dev4567).
> > L.
> >
> >
> > On 1/31/08, James Philbin <[EMAIL PROTECTED]> wrote:
> > >
> > > Hmmm. Just downloaded and installed 1.0.4 and i'm still getting this
> > > error. Are you guys using the bleeding edge version or the official
> > > 1.0.4 tarball from the webpage?
> > >
> > > James
> > > ___
> > > Numpy-discussion mailing list
> > > Numpy-discussion@scipy.org
> > > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> > >
> >
> >
> >
> > --
> > Lorenzo Bolla
> > [EMAIL PROTECTED]
> > http://lorenzobolla.emurse.com/
> >
> > ___
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
>
>
> --
> French PhD student
> Website : http://matthieu-brucher.developpez.com/
> Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
> LinkedIn : http://www.linkedin.com/in/matthieubrucher
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
from docstring in multiarraymodule.c

/** @brief Use bisection of sorted array to find first entries >= keys.
 *
 * For each key use bisection to find the first index i s.t. key <= arr[i].
 * When there is no such index i, set i = len(arr). Return the results in
ret.
 * All arrays are assumed contiguous on entry and both arr and key must be
of<-
 * the same comparable type. <-
 *
 * @param arr contiguous sorted array to be searched.
 * @param key contiguous array of keys.
 * @param ret contiguous array of intp for returned indices.
 * @return void
 */
static void
local_search_left(PyArrayObject *arr, PyArrayObject *key, PyArrayObject
*ret)

In particular:

 * All arrays are assumed contiguous on entry and both arr and key must be
of<-
 * the same comparable type. <-

A and B are not of the same type ('|S2' is not '|S1').
This should be mentioned somewhere more accessible.

L.


On 1/31/08, Alan G Isaac <[EMAIL PROTECTED]> wrote:
>
> Problem also with Windows P3 binaries.
> fwiw,
> Alan Isaac
>
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310
> 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy
> >>> numpy.__version__
> '1.0.4'
> >>> A = numpy.array(['a','aa','b'])
> >>> B = numpy.array(['d','e'])
> >>> A.searchsorted(B)
> array([3, 0])
> >>>
>
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
I use a dev version (1.0.5.dev4567).
L.


On 1/31/08, James Philbin <[EMAIL PROTECTED]> wrote:
>
> Hmmm. Just downloaded and installed 1.0.4 and i'm still getting this
> error. Are you guys using the bleeding edge version or the official
> 1.0.4 tarball from the webpage?
>
> James
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
works fine for me.


In [33]: A = numpy.array(['a','aa','b'])

In [34]: B = numpy.array(['d','e'])

In [35]: A.searchsorted(B)
Out[35]: array([3, 3])

In [36]: numpy.__version__
Out[36]: '1.0.5.dev4567'


L.




On 1/31/08, James Philbin <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> The following gives the wrong answer:
>
> In [2]: A = array(['a','aa','b'])
>
> In [3]: B = array(['d','e'])
>
> In [4]: A.searchsorted(B)
> Out[4]: array([3, 0])
>
> The answer should be [3,3]. I've come across this while trying to come
> up with an ismember function which works for strings (setmember1d
> doesn't seems to assume numerical arrays).
>
> Thanks,
> James
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread lorenzo bolla
or you can maybe use numpy.ix_:
ax = [1,2]
R[numpy.ix_(ax,ax)] = 100

hth,
L.


On 1/30/08, lorenzo bolla <[EMAIL PROTECTED]> wrote:
>
> you simply need to change the definition of ax:
> ax = slice(1,3)
>
> and all works fine.
> L.
>
>  On 1/30/08, Francesc Altet <[EMAIL PROTECTED]> wrote:
> >
> > A Wednesday 30 January 2008, Nadav Horesh escrigué:
> > > In the following piece of code:
> > > >>> import numpy as N
> > > >>> R = N.arange(9).reshape(3,3)
> > > >>> ax = [1,2]
> > > >>> R
> > >
> > > array([[0, 1, 2],
> > >[3, 4, 5],
> > >[6, 7, 8]])
> > >
> > > >>> R[ax,:][:,ax] = 100
> > > >>> R
> > >
> > > array([[0, 1, 2],
> > >[3, 4, 5],
> > >[6, 7, 8]])
> > >
> > > Why R is not updated?
> >
> > Because R[ax] is not a view of R, but another copy of the original
> > object (fancy indexing does return references to different objects).
> > In order to get views, you must specify only a slice of the original
> > array.  For example:
> >
> > In [50]: S = R[::2]
> > In [51]: S[:] = 2
> > In [52]: R
> > Out[52]:
> > array([[2, 2, 2],
> >   [3, 4, 5],
> >   [2, 2, 2]])
> >
> > So, what you need is something like:
> >
> > In [68]: R = N.arange(9).reshape(3,3)
> > In [69]: S = R[1:3,:][:,1:3]
> > In [70]: S[:] = 2
> > In [71]: R
> > Out[71]:
> > array([[0, 1, 2],
> >   [3, 2, 2],
> >   [6, 2, 2]])
> >
> > Cheers,
> >
> > --
> > >0,0<   Francesc Altet http://www.carabos.com/
> > V   V   Cárabos Coop. V.   Enjoy Data
> > "-"
> > ___
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
>
>
>
> --
> Lorenzo Bolla
> [EMAIL PROTECTED]
> http://lorenzobolla.emurse.com/




-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Can not update a submatrix

2008-01-30 Thread lorenzo bolla
you simply need to change the definition of ax:
ax = slice(1,3)

and all works fine.
L.

On 1/30/08, Francesc Altet <[EMAIL PROTECTED]> wrote:
>
> A Wednesday 30 January 2008, Nadav Horesh escrigué:
> > In the following piece of code:
> > >>> import numpy as N
> > >>> R = N.arange(9).reshape(3,3)
> > >>> ax = [1,2]
> > >>> R
> >
> > array([[0, 1, 2],
> >[3, 4, 5],
> >[6, 7, 8]])
> >
> > >>> R[ax,:][:,ax] = 100
> > >>> R
> >
> > array([[0, 1, 2],
> >[3, 4, 5],
> >[6, 7, 8]])
> >
> > Why R is not updated?
>
> Because R[ax] is not a view of R, but another copy of the original
> object (fancy indexing does return references to different objects).
> In order to get views, you must specify only a slice of the original
> array.  For example:
>
> In [50]: S = R[::2]
> In [51]: S[:] = 2
> In [52]: R
> Out[52]:
> array([[2, 2, 2],
>   [3, 4, 5],
>   [2, 2, 2]])
>
> So, what you need is something like:
>
> In [68]: R = N.arange(9).reshape(3,3)
> In [69]: S = R[1:3,:][:,1:3]
> In [70]: S[:] = 2
> In [71]: R
> Out[71]:
> array([[0, 1, 2],
>   [3, 2, 2],
>   [6, 2, 2]])
>
> Cheers,
>
> --
> >0,0<   Francesc Altet     http://www.carabos.com/
> V   V   Cárabos Coop. V.   Enjoy Data
> "-"
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] difference numpy/matlab

2008-01-29 Thread lorenzo bolla
I'd rather say "arbitrary".

On 1/29/08, Neal Becker <[EMAIL PROTECTED]> wrote:
>
> lorenzo bolla wrote:
>
> > I noticed that:
> >
> > min([1+1j,-1+3j])
> >
> > gives 1+1j in matlab (where for complex, min(abs) is used)
> > but gives -1+3j in numpy (where lexicographic order is used)
> >
> > shouldn't this be mentioned somewhere in "Numpy for Matlab users"
> webpage?
> >
>
> It should be stated that they're both wrong.
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] difference numpy/matlab

2008-01-29 Thread lorenzo bolla
I noticed that:

min([1+1j,-1+3j])

gives 1+1j in matlab (where for complex, min(abs) is used)
but gives -1+3j in numpy (where lexicographic order is used)

shouldn't this be mentioned somewhere in "Numpy for Matlab users" webpage?

-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] tensordot and axes argument

2008-01-28 Thread lorenzo bolla
Shouldn't the "axes" argument in tensordot be named "axis"?
L.

-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Failing to understand vectorize behavior

2008-01-09 Thread lorenzo bolla
Yes, 32 bits.
On a 64 bits machine, I get 8 characters long strings like you.
L.


On 1/9/08, David Huard <[EMAIL PROTECTED]> wrote:
>
> Lorenzo,
>
> 2008/1/9, lorenzo bolla <[EMAIL PROTECTED]>:
> >
> > I don't think it's expected: mine are cropped to 4 characters!
> >
>
>
> I am on a 64 bit machine. Are you on a 32 bit one ?
>
> In [101]: vstrip = vectorize( string.strip)
>
>
> > In [102]: s = ['  aa  ' , ' bb  ', '
> > cc ']
> > In [103]:
> > vstrip(s)
> >
> > Out[103]:
> >
> > array(['', '',
> > ''],
> >
> > dtype='|S4')
> >
> >
> > You can obviously use "map", instead.
> >
>
> I'll do that,
>
> Thanks,
>
>
> David
>
>  In [104]: map(string.strip,
> > s)
> > Out[104]: ['aa', 'bb',
> > 'cc']
> >
> >
> > hth,
> > L.
> >
> >
> >  On 1/9/08, David Huard < [EMAIL PROTECTED]> wrote:
> >
> > > Hi all,
> > >
> > > I'm having trouble understanding the behavior of vectorize on the
> > > following example:
> > >
> > > >>> import string
> > > >>> from numpy import vectorize
> > >
> > > >>> vstrip = vectorize( string.strip)
> > > >>> s = ['  aa  ' , ' bb  ', '
> > > cc ']
> > > >>> vstrip(s)
> > > array(['', '', ''],
> > >   dtype='|S8')
> > >
> > > where all strings are cropped to 8 characters.
> > > Is this expected ?
> > >
> > >
> > > Thanks,
> > >
> > > David
> > >
> > >
> > >
> > > ___
> > > Numpy-discussion mailing list
> > > Numpy-discussion@scipy.org
> > > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> > >
> > >
> >
> >
> > --
> > Lorenzo Bolla
> > [EMAIL PROTECTED]
> > http://lorenzobolla.emurse.com/
> > ___
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Failing to understand vectorize behavior

2008-01-09 Thread lorenzo bolla
I don't think it's expected: mine are cropped to 4 characters!

In [101]: vstrip = vectorize( string.strip)

In [102]: s = ['  aa  ' , ' bb  ', '
cc ']
In [103]:
vstrip(s)

Out[103]:

array(['', '',
''],

dtype='|S4')


You can obviously use "map", instead.

In [104]: map(string.strip, s)
Out[104]: ['aa', 'bb', 'cc']

hth,
L.


On 1/9/08, David Huard <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> I'm having trouble understanding the behavior of vectorize on the
> following example:
>
> >>> import string
> >>> from numpy import vectorize
>
> >>> vstrip = vectorize( string.strip)
> >>> s = ['  aa  ' , ' bb  ', '
> cc ']
> >>> vstrip(s)
> array(['', '', ''],
>   dtype='|S8')
>
> where all strings are cropped to 8 characters.
> Is this expected ?
>
>
> Thanks,
>
> David
>
>
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Bugs using complex192

2008-01-07 Thread lorenzo bolla
It doesn't work on Windows, either.

In [35]: numpy.sqrt(numpy.array([-1.0], dtype=numpy.complex192))
Out[35]: array([0.0+2.9996087e-305j], dtype=complex192)

In [36]: numpy.sqrt(numpy.array([-1.0], dtype=numpy.complex128))
Out[36]: array([ 0.+1.j])

In [37]: numpy.__version__
Out[37]: '1.0.5.dev4567'

hth,
L.

On 1/7/08, Matthieu Brucher <[EMAIL PROTECTED]> wrote:
>
> i,
>
> I managed to reproduce your bugs on a FC6 box :
> >>> import numpy as n
>
> >>> n.sqrt(n.array([-1.0],dtype = n.complex192))
> array([0.0+9.2747134e+492j], dtype=complex192)
>
> >>> n.sqrt(n.array([-1.0],dtype = n.complex128))
> array([ 0.+1.j])
>
> >>> x=n.array([0.0+0.0j, 1.0+0.0j], dtype=n.complex192)
> >>> x
> array([0.0+0.0j, 1.0+0.0j], dtype=complex192)
>
> >>> -x
> array([3.3621031e-4932+-1.0204727e+2057j, 1.6794099e-4932+5.5355029e-4930j],
> dtype=complex192)
>
> >>> n.__version__
> '1.0.5.dev4494'
>
> Matthieu
>
> 2008/1/7, Matts Bjoerck < [EMAIL PROTECTED]>:
> >
> > Hi,
> >
> > I've started using complex192 for some calculations and came across two
> > things
> > that seems to be bugs:
> >
> > In [1]: sqrt(array([-1.0],dtype = complex192))
> > Out[1]: array([0.0+-6.1646549e-4703j], dtype=complex192)
> >
> > In [2]: sqrt(array([-1.0],dtype = complex128))
> > Out[2]: array([ 0.+1.j])
> >
> > In [3]: x
> > Out[3]: array([0.0+0.0j, 1.0+0.0j], dtype=complex192)
> >
> > In [4]: -x
> > Out[4]: array([3.3621031e-4932+0.0012454e-5119j,
> > 1.6794099e-4932+0.0011717e-5119j], dtype=complex192)
> >
> > So, sqrt and using a negation does not seem to work. Have anyone else
> > came
> > across this as well?
> >
> > using numpy 1.0.3 on ubuntu
> >
> > Any help appriciated
> >
> > /Matts
> >
> > ___
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
>
>
>
> --
> French PhD student
> Website : http://matthieu-brucher.developpez.com/
> Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
> LinkedIn : http://www.linkedin.com/in/matthieubrucher
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] matrix multipln takes too much time

2007-12-25 Thread lorenzo bolla
you can either use matrix multiplication (see resultmatrix2) or tensordot
(see resultmatrix3).
on my computer I have:
1.15.6 sec with your code
2.0.072 sec with resultmatrix2
3.0.040 sec with tensordot (resultmatrix3) (-- which is a 400x speed)



from numpy import *

items=25
sample=5
totalcols=8100
#matrixone=matrix(zeros((items,totalcols)))
#matrixtwo=matrix(zeros((items,totalcols)))

matrixone=matrix(random.rand(items, totalcols))
matrixtwo=matrix(random.rand(items, totalcols))

resultmatrix=matrix(zeros((items,sample)))
resultmatrix2=matrix(zeros((items,sample)))
resultmatrix3=matrix(zeros((items,sample)))

# your code
for i in range(items):
for j in range(sample):
tval=0.0
for p in range(totalcols):
tval +=matrixone[ j , p ] * matrixtwo[ i , p ]
resultmatrix[ i, j ]=abs(tval)

# matrix multiplication
for i in range(items):
for j in range(sample):
resultmatrix2[ i, j ] = abs(matrixone[j,:] * matrixtwo[i,:].T)

# tensordot
resulmatrix3 = tensordot(matrixone[:sample,:], matrixtwo.T, axes=1).T

---

hth,
L.






On Dec 25, 2007 5:16 PM, Louis Wicker <[EMAIL PROTECTED]> wrote:

> Hi there - quick suggestion on Xmas morning - others are much more
> familar.
> You do not want to use a loop to do the matrix multiply, you want to use
> the intrinsic functions assoicated with matrix.
>
> So you want something like
>
> res = Math.abs( matmul(arrayone, arraytwo) )
>
> note - that is not real code, just symbolic code.  I am sure this is
> easily found in the documentation.
>
> cheers!
>
> Lou
>
>
> On Dec 25, 2007, at 8:47 AM, [EMAIL PROTECTED] om <[EMAIL PROTECTED]> w
> le-interchange-newline">
>
> hi
> i am doing some maths calculations involving matrices of double values
> using numpy.matrix ,
>
> java code for this is something like
>
> int items=25;
> int sample=5;
> int totalcols=8100;
> double[][]dblarrayone=new double[items][totalcols];
> double[][]dblarraytwo=new double[items][totalcols];
> //their elements are set elsewhere before calculation
>
> double[][] resultarray = new double[items][sample];
>
> for(int i=0;ifor(int j=0;jdouble tval=0.0;
>for(int p=0;ptval+=dblarrayone[j][p] * dblarraytwo[i][p];
>resultarray[i][j]=Math.abs(tval);
>
>}
>
> }
>
> so I wanted to do the same  in python ..(may b
> recommended way..)
> i am storing the filled matrices and other values as instance variable
> of a class and access them by self.whatever...
>
> self.items=25
> self.sample=5
> self.totalcols=8100
> #self.matrixone,self.matrixtwo are numply matix objects with already
> filled elements
> #but for testing i filled it with zeros
> self.matrixone=matrix(zeros((items,totalcols)))
> self.matrixtwo=matrix(zeros((items,totalcols)))
> resultmatrix=matrix(zeros((self.items,self.sample)))
>
> for i in range(self.items):
>for j in range(self.sample):
> tval=0.0
> for p in range(self.totalcols):
>tval +=self.matrixone[ j , p ] * self.matrixtwo[ i , p ]
> resultmatrix[ i, j ]=abs(tval)
>
>
> here I found that while the java code takes ba br>execute the code ,the
> python code takes something like 53 secs to execute !!..I am baffled
> by this ..can anyone advise me how i can improve this? (i want to code
> in python so  I can't use c,c++ , java)
>
> dn
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
> | Dr. Louis J. Wicker
> | NSSL/WRDD  Rm 4366
> | National Weather Center < "Apple-style-span" style="line-height: 16px;;
> font-size: 14px; ">
> | 120 David L. Boren Boulevard, Norman, OK 73072
> |
> | E-mail:   [EMAIL PROTECTED]
> | HTTP:  www.nssl.noaa.gov/~lwicker 
> | Phone:(405) 325-6340
> | Fax:(405) 325-6780
> |
> | "Programming is not just creating strings of instructions
> | for a computer to execute.  It's also 'literary' in that you
> | are trying to communicate a program structure to
> | other humans reading the code." - Paul Rubin
> |
> |"Real efficiency comes from elegant solutions, not optimiz ed progr
> le="font-size: 14px; ">| Optimization is always just a few
> correctness-preserving transformations
> | away." - Jonathan Sobel
>
> 
> |
> | "The contents  of this message are mine personally and
> | do not reflect any position of  the Government or NOAA."
> |
>
> 
>
>
>
>
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://proje

Re: [Numpy-discussion] setting items in a matrix

2007-12-21 Thread lorenzo bolla
or, you can either use fill.

In [53]: M = numpy.matrix(numpy.zeros((3,5)))
In [55]: M.fill(999)
In [56]: M
Out[56]:
matrix([[ 999.,  999.,  999.,  999.,  999.],
[ 999.,  999.,  999.,  999.,  999.],
[ 999.,  999.,  999.,  999.,  999.]])

L.

On 12/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> hi
> i am a beginner with numpy and python,so pardon me if this doubt seems
> silly
> i want to create a matrix with say 3 rows and 5 columns..and then set
> the values of each item in it .for this i did something like below
>
> myarray=zeros((3,5))
> #then set the items
> for row in range(3):
>for col in range(5):
>myarray[row][col]=99.
>
>
> mymatrix=matrix(myarray)
>
> is this the way to do the matrix creation and value setting?  is the
> use of  zeros() unnecessary?  i  am in the early learning stage so
> your reply wd help me much
>
> dn
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] where construct

2007-12-16 Thread lorenzo bolla
use '+' instead of 'or' for bool arrays.

In [8]: numpy.where((a<1) + (b<3), b, c)
Out[8]: array([4, 2, 2, 1])

hth,
L.

On Dec 16, 2007 8:10 PM, Ross Harder <[EMAIL PROTECTED]> wrote:

>
> What's the correct way to do something like this?
>
> a=array( (0,1,1,0) )
> b=array( (4,3,2,1) )
> c=array( (1,2,3,4) )
>
> where( (a<1 or b<3), b,c)
>
> Python throws a ValueError
> I would expect to get an array that looks like
> [4,2,2,1] I think
>
>
> Thanks,
> Ross
>
>
>
>  
> 
> Never miss a thing.  Make Yahoo your home page.
> http://www.yahoo.com/r/hs
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy : your experiences?

2007-11-20 Thread lorenzo bolla
>  a) Can you guys tell me briefly about the kind of problems you are
> > tackling with numpy and scipy?
>
>
> Electromagnetic problems: eigenvalues finding, linear systems,
> optimizations...
>
> b) Have you ever felt that numpy/scipy was slow and had to switch to
> > C/C++/Fortran?
>
>
>
> I come from that world, and python gives me the programming speed I needed
> with a more-than-reasonable executing speed. I mainly use python/numpy/scipy
> as a better Matlab, which is platform independent and free, i.e. an
> interface to numerical libraries like blas, lapack, fftw, umfpack, arpack
> and so on (which are mainly written in Fortran/C).
>
>
> c) Do you use any form of parallel processing? Multicores? SMPs?
> > Clusters? If yes how did u utilize them?
>
>
>  I use MPI (mpi4py) on a shared memory multiprocessor SGI Altix.
>

Lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Casting a float array into a string array

2007-10-05 Thread lorenzo bolla
gotcha. specify the number of bytes, then.

In [20]: x
Out[20]:
array([[-2.,  3.],
   [ 4.,  5.]])

In [21]: x.astype(numpy.dtype('S10'))
Out[21]:
array([['-2.0', '3.0'],
   ['4.0', '5.0']],
  dtype='|S10')

L.

On 10/5/07, Matthieu Brucher <[EMAIL PROTECTED]> wrote:
>
> I'd like to have the '2.', because if the number is negative, only '-' is
> returned, not the real value.
>
> Matthieu
>
> 2007/10/5, lorenzo bolla < [EMAIL PROTECTED]>:
> >
> > what's wrong with astype?
> >
> > In [3]: x = numpy.array([[2.,3.],[4.,5.]])
> >
> > In [4]: x.astype(str)
> > Out[4]:
> > array([['2', '3'],
> >['4', '5']],
> >   dtype='|S1')
> >
> > and if you want a list:
> >
> > In [5]: x.astype(str).tolist()
> > Out[5]: [['2', '3'], ['4', '5']]
> >
> >
> > L.
> >
> >
> >  On 10/5/07, Matthieu Brucher < [EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> > >
> > > I'm trying to cast a float array into a string array (for instance
> > > transforming [[2., 3.], [4., 5.]] into [['2.', '3.'], ['4.', '5.']]), I
> > > tried with astype(str) and every variation (str_, string, string_, 
> > > string0),
> > > but not luck.
> > > Is there a function or a method of the array class that can fulfill my
> > > needs ? And if there is a way to add a formatting option ('1.1f' for
> > > instance), it would be even better.
> > >
> > > Matthieu
> > >
> > > ___
> > > Numpy-discussion mailing list
> > > Numpy-discussion@scipy.org
> > > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> > >
> > >
> >
> > ___
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Casting a float array into a string array

2007-10-05 Thread lorenzo bolla
what's wrong with astype?

In [3]: x = numpy.array([[2.,3.],[4.,5.]])

In [4]: x.astype(str)
Out[4]:
array([['2', '3'],
   ['4', '5']],
  dtype='|S1')

and if you want a list:

In [5]: x.astype(str).tolist()
Out[5]: [['2', '3'], ['4', '5']]


L.


On 10/5/07, Matthieu Brucher <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm trying to cast a float array into a string array (for instance
> transforming [[2., 3.], [4., 5.]] into [['2.', '3.'], ['4.', '5.']]), I
> tried with astype(str) and every variation (str_, string, string_, string0),
> but not luck.
> Is there a function or a method of the array class that can fulfill my
> needs ? And if there is a way to add a formatting option ('1.1f' for
> instance), it would be even better.
>
> Matthieu
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] howto convert float array to array of integers

2007-10-05 Thread lorenzo bolla
what about astype?

a.astype(t) -> Copy of array cast to type t.

Cast array m to type t.  t can be either a string representing a
typecode,
or a python type object of type int, float, or complex.

L.


On 10/5/07, dmitrey <[EMAIL PROTECTED]> wrote:
>
> hi all,
> I have an array like
> array([ 1.,  0.,  2.,  -10.])
> what is most efficient (i.e. fastest) way to convert the one to array of
> integers?
> array([ 1,  0,  2,  -10])
>
> Thx in advance, D.
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] arange and floating point arguments

2007-09-14 Thread lorenzo bolla
this is really annoying.
Matlab handles the "ceil" weirdness quite well, though.

--

>> ceil(0.6/0.1)

ans =

 6

>> ceil((0.4+0.2)/0.1)

ans =

 7

>> 0:0.1:0.6

ans =

 01.000e-001
2.000e-0013.000e-0014.000e-001
5.000e-0016.000e-001

>> 0:0.1:(0.4+0.2)

ans =

 01.000e-001
2.000e-0013.000e-0014.001e-001
5.001e-0016.001e-001


>> length(0:0.1:0.6) == length(0:0.1:(0.4+0.2))

ans =

 1

--

hth,

L.



On 9/14/07, Ed Schofield <[EMAIL PROTECTED]> wrote:
>
> Hi everyone,
>
> This was reported yesterday as a bug in Debian's numpy package:
>
> >>> len(numpy.arange(0, 0.6, 0.1)) == len(numpy.arange(0, 0.4+0.2, 0.1))
> False
>
> The cause is this:
>
> >>> ceil((0.4+0.2)/0.1)
> 7.0
>
> >>> ceil(0.6/0.1)
> 6.0
>
> which holds for both numpy's and the standard library's ceil().
>
> Using arange in this way is a fundamentally unreliable thing to do,
> but is there anything we want to do about this? Should numpy emit a
> warning when using arange with floating point values when
> (stop-start)/step is close to an integer?
>
> -- Ed
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread lorenzo bolla
maybe numpy.vdot is good for you.

In [3]: x = numpy.random.rand(4)

In [4]: x
Out[4]: array([ 0.45426898,  0.22369238,  0.98731244,  0.7758774 ])

In [5]: numpy.sqrt(numpy.vdot(x,x))
Out[5]: 1.35394615117

hth,
lorenzo


On 9/5/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Oh I think I get it.
>
> You mean the built-in len() function? This isn't what I am looking for.
> len() returns the number of components in the vector (e.g. whether it is a
> 2D, 3D, etc vector). I found that magnitude can be calculated using hypot()
> in the math module that comes with python. However, this method only appears
> to work with 2D vectors. And yes, by magnitude I mean euclidean norm:
>
> sqrt( x*x + y*y ) = magnitude (length) of a vector
>
> On 9/5/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> >
> > Thanks for your response.
> >
> > I was not able to find len() in the numpy documentation at the following
> > link:
> > http://www.scipy.org/doc/numpy_api_docs/namespace_index.html
> >
> > Perhaps I'm looking in the wrong location?
> >
> > On 9/5/07, Matthieu Brucher < [EMAIL PROTECTED] > wrote:
> >
> > >
> > >
> > > 2007/9/5, Robert Dailey < [EMAIL PROTECTED]>:
> > > >
> > > > Hi,
> > > >
> > > > I have two questions:
> > > >
> > > > 1) Is there any way in numpy to represent vectors? Currently I'm
> > > > using 'array' for vectors.
> > >
> > >
> > >
> > > A vector is an array with one dimension, it's OK. You could use a
> > > matrix of dimension 1xn or nx1 as well.
> > >
> > >
> > > 2) Is there a way to calculate the magnitude (length) of a vector in
> > > > numpy?
> > >
> > >
> > > Yes, len(a)
> > >
> > > Matthieu
> > >
> > > ___
> > > Numpy-discussion mailing list
> > > Numpy-discussion@scipy.org
> > > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> > >
> > >
> >
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy installation problem

2007-08-08 Thread lorenzo bolla
sorry for the silly question: have you done
"python setup.py install"
from the numpy src directory, after untarring?
then cd out from the src directory and try to import numpy from python.
L.


On 7/31/07, kingshuk ghosh <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I downloaded numpy1.0.3-2.tar and unzipped and untared.
> However somehow new numpy does not work. It invokes
> the old numpy 0.9.6 when i import numpy from python
> and type in numpy.version.version .
> I tried to change path and once I do that and when I do
> import numpy it says
> "running from source directory" and then if I try
> numpy.version.version it gives some error.
>
> Is there something obvious I am missing after unzipping
> and untaring the numpy source file ? For example do I need
> to do something to install the new numpy1.0.3 ?
>
> Or do I also need to download full python package ?
> I am trying to run this on Red Hat Linux 3.2.2-5 which
> has a gcc 3.2.2 and the version of python is 2.4 .
>
> Any help will be greatly appreciated.
>
> Cheers
> Kings
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] expm

2007-07-20 Thread lorenzo bolla

hi all.
is there a function in numpy to compute the exp of a matrix, similar to expm
in matlab?
for example:
expm([[0,0],[0,0]]) = eye(2)

thanks,
lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] f2py and openmp

2007-07-05 Thread lorenzo bolla

hi all,
I'm using f2py to compile a f90 function, parallelized with openmp, into a
shared object, that I can import in python.
the question is: when I call the function from python, how can I specify the
number of threads to use?
the usual way of doing it, with a common fortran executable, is setting the
enviroment variable OMP_NUM_THREADS to the desired value.
using os.environ to set it from python does not seem to work: the function
is always executed using 4 processors (that is quite strange in itself:
where does "4" comes from?).
any hints?
thank you all in advance,
lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] f2py and type construct

2007-06-18 Thread lorenzo bolla

hi all.
I'm trying to compile an F90 source file with f2py, but it fails with the
construct "type ... end type".
here is an example:


! file test19.f90
module
basic
 implicit
none


save
 integer, parameter :: ciao =
17

end module
basic



module
basic2
 implicit
none


save
 type
test_t

integer ::
x

 end type
test_t
 type(test_t) ::
ciao

end module
basic2

--

$>f2py -c test19.f90 -m test --fcompiler=intele --compiler=intel
(I'm compiling on an SGI Altix)

and this is the error message:

--
running build
running config_fc
running build_src
building extension "test" sources
f2py options: []
f2py:> /tmp/tmprBrnf7/src.linux-ia64-2.5/testmodule.c
creating /tmp/tmprBrnf7
creating /tmp/tmprBrnf7/src.linux- ia64-2.5
Reading fortran codes...
   Reading file 'test19.f90' (format:free)
Post-processing...
   Block: test
   Block: basic
   Block: basic2
   Block: test_t
Post-processing (stage 2)...
   Block: test
   Block: unknown_interface
   Block: basic
   Block: basic2
   Block: test_t
Building modules...
   Building module "test"...
   Constructing F90 module support for "basic"...
 Variables: ciao
   Constructing F90 module support for "basic2"...
 Variables: ciao
getctype: No C-type found in "{'typespec': 'type', 'typename': 'test_t'}",
assuming void.
Traceback (most recent call last):
 File "/xlv1/labsoi_devices/bollalo001/bin/f2py", line 26, in 
   main()
 File 
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f2py2e.py",
line 552, in main
   run_compile()
 File 
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f2py2e.py",
line 539, in run_compile
   setup(ext_modules = [ext])
 File 
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/distutils/core.py",
line 174, in setup
   return old_setup(**new_attr)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/core.py",
line 151, in setup
   dist.run_commands()
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/dist.py",
line 974, in run_commands
   self.run_command(cmd)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/dist.py",
line 994, in run_command
   cmd_obj.run()
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/command/build.py",
line 112, in run
   self.run_command(cmd_name)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/cmd.py",
line 333, in run_command
   self.distribution.run_command(command)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/dist.py",
line 994, in run_command
   cmd_obj.run()
[...]
KeyError: 'void'
Exit 1


module basic gives no problems, but module basic2 yes, because of the type
construct.
it seems that f2py doesn't support "type" construct. am I right? is there a
workaround?
thank you very much,
lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] f2py and type construct

2007-06-15 Thread lorenzo bolla

hi all.
I'm trying to compile an F90 source file with f2py, but it fails with the
construct "type ... end type".
here is an example:


! file test19.f90
module
basic



 implicit
none


save



 integer, parameter :: ciao =
17



end module
basic



module
basic2



 implicit
none


save



 type
test_t

integer ::
x

 end type
test_t



 type(test_t) ::
ciao



end module
basic2
--

$>f2py -c test19.f90 -m test --fcompiler=intele --compiler=intel
(I'm compiling on an SGI Altix)

and this is the error message:

--
running build
running config_fc
running build_src
building extension "test" sources
f2py options: []
f2py:> /tmp/tmprBrnf7/src.linux-ia64-2.5/testmodule.c
creating /tmp/tmprBrnf7
creating /tmp/tmprBrnf7/src.linux-ia64-2.5
Reading fortran codes...
   Reading file 'test19.f90' (format:free)
Post-processing...
   Block: test
   Block: basic
   Block: basic2
   Block: test_t
Post-processing (stage 2)...
   Block: test
   Block: unknown_interface
   Block: basic
   Block: basic2
   Block: test_t
Building modules...
   Building module "test"...
   Constructing F90 module support for "basic"...
 Variables: ciao
   Constructing F90 module support for "basic2"...
 Variables: ciao
getctype: No C-type found in "{'typespec': 'type', 'typename': 'test_t'}",
assuming void.
Traceback (most recent call last):
 File "/xlv1/labsoi_devices/bollalo001/bin/f2py", line 26, in 
   main()
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f2py2e.py",
line 552, in main
   run_compile()
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f2py2e.py",
line 539, in run_compile
   setup(ext_modules = [ext])
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/distutils/core.py",
line 174, in setup
   return old_setup(**new_attr)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/core.py",
line 151, in setup
   dist.run_commands()
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/dist.py",
line 974, in run_commands
   self.run_command(cmd)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/dist.py",
line 994, in run_command
   cmd_obj.run()
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/command/build.py",
line 112, in run
   self.run_command(cmd_name)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/cmd.py",
line 333, in run_command
   self.distribution.run_command(command)
 File "/xlv1/labsoi_devices/bollalo001/lib/python2.5/distutils/dist.py",
line 994, in run_command
   cmd_obj.run()
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/distutils/command/build_src.py",
line 87, in run
   self.build_sources()
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/distutils/command/build_src.py",
line 106, in build_sources
   self.build_extension_sources(ext)
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/distutils/command/build_src.py",
line 218, in build_extension_sources
   sources = self.f2py_sources(sources, ext)
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/distutils/command/build_src.py",
line 471, in f2py_sources
   ['-m',ext_name]+f_sources)
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f2py2e.py",
line 362, in run_main
   ret=buildmodules(postlist)
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f2py2e.py",
line 314, in buildmodules
   dict_append(ret[mnames[i]],rules.buildmodule(modules[i],um))
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/rules.py",
line 1130, in buildmodule
   mr,wrap = f90mod_rules.buildhooks(m)
 File
"/xlv1/labsoi_devices/bollalo001/lib/python2.5/site-packages/numpy/f2py/f90mod_rules.py",
line 127, in buildhooks
   at = capi_maps.c2capi_map[ct]
KeyError: 'void'
Exit 1


module basic gives no problems, but module basic2 yes, because of the type
construct.
what am I doing wrong?
thank you very much,
lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] fortran representation

2007-05-31 Thread lorenzo bolla

Hi all,
I've got an easy question for you. I looked in Travis' book, but I couldn't
figure out the answer...

If I have an array1D (obtained reading a stream of numbers with
numpy.fromfile) like that:

In [150]: data
Out[150]: array([ 2.,  3.,  4.,  3.,  4.,  5.,  4.,  5.,  6.,  5.,  6.,
7.], dtype=float32)

I want it to be considered as "Fortran ordered", so that when I do:

In [151]: data.shape = (3,4)

I want to get:

array([[ 2.,  3.,  4.,  5.],
  [ 3.,  4.,  5.,  6.],
  [ 4.,  5.,  6.,  7.]], dtype=float32)

But I get:

array([[ 2.,  3.,  4.,  3.],
  [ 4.,  5.,  4.,  5.],
  [ 6.,  5.,  6.,  7.]], dtype=float32)

How can I do that?
(I know I could do data.reshape(4,3).T, but it's not very "elegant" and
reshaping in ND becomes a mess!).
(I tried with numpy.array(data, order = 'Fotran'), with no luck...)

Thank you in advance,
Lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] IEEE floating point arithmetics

2007-05-26 Thread lorenzo bolla

Hi all.
I have to work with floating point arithmetics and I found a module called
"double module" (http://symptotic.com/mj/double/public/double-module.html)
that does what I'd like. Basically, I would like to find the nearest smaller
and bigger floating point numbers, given a "real" real number (the function
doubleToLongBits
can
be used to do just that.).
Is there something similar in numpy?
In other words: is there a way, in numpy, to convert a floating point number
to its binary representation and back?
Thank you and regards,
L.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] f2py and C functions/subroutines/structs

2007-05-24 Thread lorenzo bolla

I tried to write my own prova2.pyf and this is it:



!-*- f90 -*-
! Note: the context of this file is case sensitive.

python module prova

interface

  function incr(x)
real, dimension(2), intent(c) :: incr
real, dimension(2), intent(c,in) :: x
  end function incr

  function incr0(x)
integer intent(c) :: incr0
integer intent(c,in) :: x
  end function incr0

  subroutine incr1(x)
intent(c) :: incr1
integer intent(c,in,out) :: x
  end subroutine incr1

end interface

end python module prova

! This file was auto-generated with f2py (version:2_3473).
! See http://cens.ioc.ee/projects/f2py2e/




Unfortunately, only the function incr0 works.
incr1 gives a segmentation fault and incr does not return an array (or
better a struct) as I would...
any hints?

thank you!
L.





On 5/24/07, Pierre GM <[EMAIL PROTECTED]> wrote:


Lorenzo,
you can indeed use f2py to write extensions around some C code:

http://cens.ioc.ee/projects/f2py2e/usersguide/index.html
http://www.scipy.org/Cookbook/f2py_and_NumPy

I think you should also be able to find some actual examples in the scipy
sources...
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] f2py and C functions/subroutines/structs

2007-05-24 Thread lorenzo bolla

Hi all,
I hope this is the right mailing list to post my question to.
I'm trying to make some easy C code working with Python by using f2py.

For example, take the test.c file:

--

typedef struct data {
int a;
double b;
} DATA;

/*function with struct*/
DATA incr(DATA x) {
DATA y;
y.a = x.a + 1;
y.b = x.b + 1.;
return(y);
}

/*function: return value*/
int incr0(int x) {
return(x+1);
}

/*subroutine: no return value*/
void incr1(int *x) {
*x += 1;
}
--




If I do:
$ f2py -c test.c -m prova
all seems fine, but inside ipython I get this error:

In [1]: import prova
---
   Traceback (most recent call last)

/xlv1/labsoi_devices/bollalo001/work/test/python/ in
()

: dynamic module does not define init
function (initprova)


I think I'm missing a correct .pyf file to do:
$ f2py -c prova2.pyf test.c

I tried writing prova2.pyf by my own, because doing:
$ f2py test.c -h prova2.pyf -m prova
gives me an empty prova2.pyf, but I wasn't able to do it!!!

Can anyone of use kindly show me how to write it? Or giving me a good
tutorial to read? I found only very few information on www.scipy.org.

Thank you in advance,
Lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] BLAS and LAPACK used?

2007-05-17 Thread lorenzo bolla

Hi all,
I need to know the libraries (BLAS and LAPACK) which numpy has been linked
to, when I compiled it.
I can't remember which ones I used (ATLAS, MKL, etc...)...
Is there an easy way to find it out?
Thanks in advance,
Lorenzo Bolla.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] arctan2 with complex args

2007-04-30 Thread lorenzo bolla

hold on, david. the formula I posted previously from wolfram is ArcTan[x,y]
with x or y complex: its the same of arctan2(x,y). arctan is another
function (even though arctan2(y,x) should be "a better" arctan(y/x)).

the correct formula for y = arctan(x), with any x (real or complex), should
be (if I still can play with sin and cos...):

y = arctan(x) = 1/(2j) * log((1j-x)/(1j+x))

[ you can get it doing: y = arctan(x) --> x = tan(y) = sin(x)/cos(x) = -1j *
(exp(1j*y)-exp(-1j*y))/(exp(1j*y)+exp(-1j*y); then let z = exp(1j*y) and
solve in z.]

I've tested the formula and it seems ok for different inputs (I've checked
that tan(arctan(x)) == x):
---
octave:56> x = 1; tan(1/2/1j*log((1j-x)/(1j+x)))
ans = 1.
octave:57> x = 1j; tan(1/2/1j*log((1j-x)/(1j+x)))
ans = -0 + 1i
octave:58> x = 2j; tan(1/2/1j*log((1j-x)/(1j+x)))
ans = 1.8369e-16 + 2.e+00i
octave:59> x = 1+2j; tan(1/2/1j*log((1j-x)/(1j+x)))
ans = 1. + 2.i
---

hth,
L.

On 4/30/07, David Goldsmith <[EMAIL PROTECTED]> wrote:



> (hint what is arctan(0+1j)?)
>
Well, at the risk of embarrassing myself, using arctan(x+iy) = I get:

arctan(0+1i) = -i*log((0+i*1)/sqrt(0^2 + 1^2)) = -i*log(i/1) = -i*log(i)
= -i*log(exp(i*pi/2)) = -i*i*pi/2 = pi/2...

Is there some reason I'm forgetting (e.g., a branch cut convention or
something) why this is wrong?

DG
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] can't import repmat from numpy

2007-04-30 Thread lorenzo bolla

it looks like repmat is not there anymore... why?
use numpy.repeat and numpy.tile, instead!
hth,
lorenzo.

On 4/30/07, dmitrey <[EMAIL PROTECTED]> wrote:


What's wrong?

start python shell;

from numpy import sin   => all ok

from numpy import repmat =>
Traceback (most recent call last):
  File "", line 1, in 
ImportError: cannot import name repmat


D.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] arctan2 with complex args

2007-04-30 Thread lorenzo bolla

me!
I have two cases.

  1. I need that arctan2(1+0.0001j,1-0.01j) gives something
  close to arctan2(1,1): any decent analytic prolungation will do!
  2. if someone of you is familiar with electromagnetic problems, in
  particular with Snell's law, will recognize that in case of total
  internal reflectionthe
wavevector tangential to the interface is real, while the normal one
is
  purely imaginary: hence the angle of diffraction is still given by
  arctan2(k_tangent, k_normal), that, as in Matlab or Octave, should give pi/2
  (that physically means no propagation -- total internal reflection, as
  said).

L.

On 4/30/07, Anne Archibald <[EMAIL PROTECTED]> wrote:


On 29/04/07, David Goldsmith <[EMAIL PROTECTED]> wrote:
> Far be it from me to challenge the mighty Wolfram, but I'm not sure that
> using the *formula* for calculating the arctan of a *single* complex
> argument from its real and imaginary parts makes any sense if x and/or y
> are themselves complex (in particular, does Lim(formula), as the
> imaginary part of complex x and/or y approaches zero, approach
> arctan2(realpart(x), realpart(y)?) - without going to the trouble to
> determine it one way or another, I'd be surprised if "their"
> continuation of the arctan2 function from RxR to CxC is (a. e.)
> continuous (not that I know for sure that "mine" is...).

Well, yes, in fact, theirs is continuous, and in fact analytic, except
along the branch cuts (which they describe). Formulas almost always
yield continuous functions apart from easy-to-recognize cases. (This
can be made into a specific theorem if you're determined.)

Their formula is a pretty reasonable choice, given that it's not at
all clear what arctan2 should mean for complex arguments. But for
numpy it's tempting to simply throw an exception (which would catch
quite a few programmer errors that would otherwise manifest as
nonsense numbers). Still, I suppose defining it on the complex numbers
in a way that is continuous close to the real plane allows people to
put in almost-real complex numbers and get out pretty much the answer
they expect. Does anyone have an application for which they need
arctan2 of, say, (1+i,1-i)?

Anne
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] arctan2 with complex args

2007-04-29 Thread lorenzo bolla

You make your point, but I would expect a behaviour similar to Mathematica
or Matlab.


From http://documents.wolfram.com/mathematica/functions/ArcTan

"If x or y is complex, then ArcTan[x, y] gives . When , ArcTan[x, y] gives
the number such that and ."

Lorenzo.

On 4/29/07, David Goldsmith <[EMAIL PROTECTED]> wrote:


I'll take a stab at this one; if I miss the mark, people, please chime in.

What's "strange" here is not numpy's behavior but octave's (IMO).
Remember that, over R, arctan is used in two different ways: one is
simply as a map from (-inf, inf) -> (-pi/2,pi/2) - here, let's call that
invtan; the other is as a means to determine "the angle" (conventionally
taken to be between -pi and pi) of a point in the plane - but since, for
example, tan(pi/4) = tan(-3pi/4) (and in general tan(x) = tan(x-pi)) to
uniquely determine said angle, we need to keep track of and take into
account the quadrant in which the point lies; this is (the only reason)
why arctan2 is a function of two arguments, one representing the
abscissa, the other the ordinate of the point.  But when the argument is
complex (arctan2, as the inverse of the tangent function, *is* a valid
function on C), this geometric use no longer makes sense, so there's
really no reason to implement arctan2(z,w), z, w complex.  If for some
reason, e.g., uniformity of algorithmic expression - I don't see any
(simple) way to preserve uniformity of code expression - as near as I
can tell, you're going to have to implement an if/else if you need to
allow for the invtan of two complex arguments - you need to handle
arctan2(z,w), implement it as arctan(w/z):

>>> import numpy
>>> numpy.arctan(1j/1j)
(0.78539816339744828+0j)

DG

lorenzo bolla wrote:
> Weird behaviour with arctan2(complex,complex).
> Take  a look at this:
>
> In [11]: numpy.arctan2(1.,1.)
> Out[11]: 0.785398163397
>
> In [12]: numpy.arctan2(1j,1j)
>
---
> exceptions.AttributeErrorTraceback (most
> recent call last)
>
> AttributeError: 'complex' object has no attribute 'arctan2'
>
> same error for:
>
> In [13]: numpy.arctan2(1j,1.)
> In [14]: numpy.arctan2(1.,1j)
>
> But arctan2 is defined for complex arguments, as far as Octave knows :-)
:
>
> octave:7> atan2(1,1)
> ans = 0.78540
> octave:8> atan2(1j,1j)
> ans = 0
> octave:9> atan2(1j,1)
> ans = 0
> octave:10> atan2(1,1j)
> ans = 1.5708
>
> bug or wanted behaviour?
> Lorenzo.
> 
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] arctan2 with complex args

2007-04-29 Thread lorenzo bolla

Weird behaviour with arctan2(complex,complex).
Take  a look at this:

In [11]: numpy.arctan2(1.,1.)
Out[11]: 0.785398163397

In [12]: numpy.arctan2(1j,1j)
---
exceptions.AttributeErrorTraceback (most recent
call last)

AttributeError: 'complex' object has no attribute 'arctan2'

same error for:

In [13]: numpy.arctan2(1j,1.)
In [14]: numpy.arctan2(1.,1j)

But arctan2 is defined for complex arguments, as far as Octave knows :-) :

octave:7> atan2(1,1)
ans = 0.78540
octave:8> atan2(1j,1j)
ans = 0
octave:9> atan2(1j,1)
ans = 0
octave:10> atan2(1,1j)
ans = 1.5708

bug or wanted behaviour?
Lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Problem with roots and complex coefficients

2007-04-19 Thread lorenzo bolla

updated.
now it works. many thanks.
L.

On 4/19/07, Nils Wagner <[EMAIL PROTECTED]> wrote:


lorenzo bolla wrote:
> dear all,
> I've some problems with numpy.roots.
> take a look at the following code:
>
> 
> import numpy
>
> OK = numpy.roots([1, 1, 1])
> OK = numpy.roots([1j, 1])
> KO = numpy.roots([1, 1j, 1])
> 
>
> it fails with this error message, trying to execute the last line:
>
> TypeError: can't convert complex to float; use
> abs(z)/usr/lib/python2.4/site-packages/numpy/lib/polynomial.py in
> roots(p)
> 119 if N > 1:
> 120 # build companion matrix and find its eigenvalues (the
> roots)
> --> 121 A = diag(NX.ones((N-2,), p.dtype), -1)
> 122 A[0, :] = -p[1:] / p[0]
> 123 roots = _eigvals(A)
>
> /usr/lib/python2.4/site-packages/numpy/lib/twodim_base.py in diag(v, k)
>  66 i = arange(0,n+k)
>  67 fi = i+(i-k)*n
> ---> 68 res.flat[fi] = v
>  69 return res
>  70 elif len(s)==2:
>
> TypeError: can't convert complex to float; use abs(z)
>
> any ideas?
> thanks,
> Lorenzo
>
> 
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
Works fine for me. Maybe you are using an old numpy version.

>>> from numpy import *
>>> roots([1, 1, 1])
array([-0.5+0.8660254j, -0.5-0.8660254j])
>>> roots([1j, 1])
array([-0.+1.j])
>>> roots([1, 1j, 1])
array([  0.e+00-1.61803399j,   1.38777878e-17+0.61803399j])
>>> import numpy
>>> numpy.__version__
'1.0.3.dev3716'


Nils

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Problem with roots and complex coefficients

2007-04-19 Thread lorenzo bolla

dear all,
I've some problems with numpy.roots.
take a look at the following code:


import numpy

OK = numpy.roots([1, 1, 1])
OK = numpy.roots([1j, 1])
KO = numpy.roots([1, 1j, 1])


it fails with this error message, trying to execute the last line:

TypeError: can't convert complex to float; use
abs(z)/usr/lib/python2.4/site-packages/numpy/lib/polynomial.py in roots(p)
   119 if N > 1:
   120 # build companion matrix and find its eigenvalues (the
roots)
--> 121 A = diag(NX.ones((N-2,), p.dtype), -1)
   122 A[0, :] = -p[1:] / p[0]
   123 roots = _eigvals(A)

/usr/lib/python2.4/site-packages/numpy/lib/twodim_base.py in diag(v, k)
66 i = arange(0,n+k)
67 fi = i+(i-k)*n
---> 68 res.flat[fi] = v
69 return res
70 elif len(s)==2:

TypeError: can't convert complex to float; use abs(z)

any ideas?
thanks,
Lorenzo
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] NumPy benchmark

2007-04-18 Thread lorenzo bolla

the amazing performance of C++ code does not surprise me: a tenfold
improvement of the simple Python/Numpy code can be achieved with
weave.inline or Pyrex.

Hence your benchmarks seems to confirm that "weaved" or "pyrexed" code run
as fast as C++ compiled one.

Moreover, from your numbers, I can tell that compiling numpy with gcc or icc
makes no big difference.

Am I correct?

If yes, let me know if I can add this info to the scipy wiki: I'm preparing
an extention to this page http://www.scipy.org/PerformancePython.

cheers,
lorenzo




On 4/17/07, rex <[EMAIL PROTECTED]> wrote:


lorenzo bolla <[EMAIL PROTECTED]> [2007-04-17 00:37]:
> as soon as you do it, I'd like to compare them with the benchmarks I
posted
> here few days ago (compiled with gcc):


http://lbolla.wordpress.com/2007/04/11/numerical-computing-matlab-vs-pythonnumpyweave/

Thanks for the link.

I haven't built numpy with MKL 9.1 yet, but here are some results
running laplace.py using MKL 8.1. The CPU is a Core 2 Duo (currently)
overclocked to 2.94 GHz (it will run at 3.52 GHz).

Using Python2.5 compiled with icc 9.1, numpy built with MKL 8.1
Doing 100 iterations on a 500x500 grid
numeric took 1.53 seconds
slow (100 iterations) took 130.02 seconds
slow with Psyco (100 iterations) took 107.91 seconds

Python compiled with icc takes 85 times longer to run this benchmark
than Python/NumPy does.

Using Python2.5 compiled with gcc, numpy built with MKL 8.1
Doing 100 iterations on a 500x500 grid
numeric took 1.57 seconds
slow (100 iterations) took 154.29 seconds
slow with Psyco (100 iterations) took 119.88 seconds

Python compiled with gcc takes 101 times longer to run this benchmark
than Python/NumPy/icc does.

The C++ version compiled with gcc 4.1.2 runs in .19 seconds.

-rex
--
I liked Occam's razor so much I bought the company.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] NumPy benchmark

2007-04-17 Thread lorenzo bolla

as soon as you do it, I'd like to compare them with the benchmarks I posted
here few days ago (compiled with gcc):
http://lbolla.wordpress.com/2007/04/11/numerical-computing-matlab-vs-pythonnumpyweave/

lorenzo.

On 4/17/07, rex <[EMAIL PROTECTED]> wrote:


I'm about to build numpy using Intel's MKL 9.1 beta and want to compare
it with the version I built using MKL 8.1. Is the LINPACK
benchmark the most appropriate?

Thanks,

-rex
--
Pollytheism: n., the belief that there are many gods, all of them parrots.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] efficient norm of a vector

2007-03-14 Thread lorenzo bolla

thanks. I hadn't seen it.

anyway, from very rough benchmarks I did, the quickest and easiest way of
computing the euclidean norm of a 1D array is:
n = sqrt(dot(x,x.conj()))
much faster than:
n = sqrt(sum(abs(x)**2))
and much much faster than:
n = scipy.linalg.norm(x)

regards,
lorenzo.


On 3/14/07, Bill Baxter <[EMAIL PROTECTED]> wrote:


There is numpy.linalg.norm.

Here's what it does:

def norm(x, ord=None):
   x = asarray(x)
   nd = len(x.shape)
   if ord is None: # check the default case first and handle it
immediately
   return sqrt(add.reduce((x.conj() * x).ravel().real))
   if nd == 1:
   if ord == Inf:
   return abs(x).max()
   elif ord == -Inf:
   return abs(x).min()
   elif ord == 1:
   return abs(x).sum() # special case for speedup
   elif ord == 2:
   return sqrt(((x.conj()*x).real).sum()) # special case for
speedup
   else:
   return ((abs(x)**ord).sum())**(1.0/ord)
   elif nd == 2:
   if ord == 2:
   return svd(x, compute_uv=0).max()
   elif ord == -2:
   return svd(x, compute_uv=0).min()
   elif ord == 1:
   return abs(x).sum(axis=0).max()
   elif ord == Inf:
   return abs(x).sum(axis=1).max()
   elif ord == -1:
   return abs(x).sum(axis=0).min()
   elif ord == -Inf:
   return abs(x).sum(axis=1).min()
   elif ord in ['fro','f']:
   return sqrt(add.reduce((x.conj() * x).real.ravel()))
   else:
   raise ValueError, "Invalid norm order for matrices."
   else:
   raise ValueError, "Improper number of dimensions to norm."



--bb



On 3/14/07, lorenzo bolla <[EMAIL PROTECTED]> wrote:
> Hi all,
> just a quick (and easy?) question.
> what is the best (fastest) way to implement the euclidean norm of a
vector,
> i.e. the function:
>
> import scipy as S
> def norm(x):
>"""normalize a vector."""
>return S.sqrt(S.sum(S.absolute(x)**2))
>
> ?
>
> thanks in advance,
> Lorenzo.
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] efficient norm of a vector

2007-03-13 Thread lorenzo bolla

Hi all,
just a quick (and easy?) question.
what is the best (fastest) way to implement the euclidean norm of a vector,
i.e. the function:

import scipy as S
def norm(x):
  """normalize a vector."""
  return S.sqrt(S.sum(S.absolute(x)**2))

?

thanks in advance,
Lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Python EM Project

2007-01-10 Thread lorenzo bolla

Hi all, I'm not sure if I am slightly out of topic, but I can't find
information anywhere else.
Can someone tell me where the Python EM Project has gone? The website
www.pythonemproject.com that used to host it is now a bunch of ads, property
of DomainDrop. Also Robert Lytle, who seemed to be "responsible" for the
project, cannot be contacted via e-mail.
Thank you!
Lorenzo
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] reduction

2007-01-08 Thread lorenzo bolla

ops. I did it, too.
should I delete it?? how??
thanks!

On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:




On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:
>
>
>
> On 1/8/07, lorenzo bolla < [EMAIL PROTECTED]> wrote:
> >
> > Well, I don't know if we should consider it a bug, but it definetely
> > behaves not as expected by the standard "reduce", right?
> > I'm very happy to help: just tell me how to "file a ticket"! (what
> > does it mean, by the way?).
> > thanks!
> >
>
> Go to http://projects.scipy.org/scipy/numpy, on the top right of the
> page there will be a menu.  You need to be registered to log in and file a
> new ticket, so you might need to do that first. After registration, log in
> and a menu item for a new ticket will show up. Click on it and continue.
>

Never mind, Robert already filed ticket # 413.

Chuck


___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] reduction

2007-01-08 Thread lorenzo bolla

oh, I forgot. It happens with "divide", too.
lorenzo.


On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:




 On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:
>
>
>
> On 1/8/07, lorenzo bolla < [EMAIL PROTECTED]> wrote:
> >
> > Hello all!
> > I'm fairly new to Numpy and, while experimenting, I found a strange (
> > i.e. not expected by me!) behaviour of arrays.
> > I tried this (in comment what I get):
> >
> > x = arange(4)  # x = array([0,1,2,3])
> >
> > def myadd(x,y):# re-define the binary sum function
> > return x + y
> >
> > reduce(myadd, x) # 6, as expected
> >  add.reduce(x) # 6, as expected
> >
> > def mysub(x,y):   # re-define the binary diff function
> > return x - y
> >
> > reduce(mysub, x)# -6, as expected
> > subtract.reduce(x)# 2 ---> WHY?
> >
>
> It might be a bug in the implementation. What is happening is that
> instead of subtracting the new number from the previous result, the previous
> result is being subtracted from the new number. So you start with 0, and the
> sequence of operations continues:
>
> 0 = 0 - 0
> 1 = 1 - 0
> 1 = 2 - 1
> 2 = 3 - 1
> 2 = 4 - 2
> 3 = 5 - 2
>
> Definitely a bug. Want to file a ticket?
>

Or maybe not a bug. It depends on what reduce means for this operation. So
either a bug or something that could use a bit of documentation.

Chuck



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] reduction

2007-01-08 Thread lorenzo bolla

Well, I don't know if we should consider it a bug, but it definetely behaves
not as expected by the standard "reduce", right?
I'm very happy to help: just tell me how to "file a ticket"! (what does it
mean, by the way?).
thanks!
lorenzo.


On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:




 On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:
>
>
>
> On 1/8/07, lorenzo bolla < [EMAIL PROTECTED]> wrote:
> >
> > Hello all!
> > I'm fairly new to Numpy and, while experimenting, I found a strange (
> > i.e. not expected by me!) behaviour of arrays.
> > I tried this (in comment what I get):
> >
> > x = arange(4)  # x = array([0,1,2,3])
> >
> > def myadd(x,y):# re-define the binary sum function
> > return x + y
> >
> > reduce(myadd, x) # 6, as expected
> >  add.reduce(x) # 6, as expected
> >
> > def mysub(x,y):   # re-define the binary diff function
> > return x - y
> >
> > reduce(mysub, x)# -6, as expected
> > subtract.reduce(x)# 2 ---> WHY?
> >
>
> It might be a bug in the implementation. What is happening is that
> instead of subtracting the new number from the previous result, the previous
> result is being subtracted from the new number. So you start with 0, and the
> sequence of operations continues:
>
> 0 = 0 - 0
> 1 = 1 - 0
> 1 = 2 - 1
> 2 = 3 - 1
> 2 = 4 - 2
> 3 = 5 - 2
>
> Definitely a bug. Want to file a ticket?
>

Or maybe not a bug. It depends on what reduce means for this operation. So
either a bug or something that could use a bit of documentation.

Chuck



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] reduction

2007-01-08 Thread lorenzo bolla

Hello all!
I'm fairly new to Numpy and, while experimenting, I found a strange (i.e.
not expected by me!) behaviour of arrays.
I tried this (in comment what I get):

x = arange(4)  # x = array([0,1,2,3])

def myadd(x,y):# re-define the binary sum function
   return x + y

reduce(myadd, x) # 6, as expected
add.reduce(x) # 6, as expected

def mysub(x,y):   # re-define the binary diff function
   return x - y

reduce(mysub, x)# -6, as expected
subtract.reduce(x)# 2 ---> WHY?

Can someone explain me this?
Thank you in advance!
lorenzo.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion