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

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

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 [

[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 s

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

2008-04-25 Thread lorenzo bolla
l 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/

Re: [Numpy-discussion] Fromfunction generalization

2008-04-22 Thread lorenzo bolla
__ > 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] 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)

[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

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

2008-03-31 Thread lorenzo bolla
; 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/

Re: [Numpy-discussion] greedy loadtxt

2008-03-27 Thread lorenzo bolla
t; 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? >

[Numpy-discussion] greedy loadtxt

2008-03-27 Thread lorenzo bolla
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:

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

2008-03-26 Thread lorenzo bolla
) 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

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

2008-03-26 Thread lorenzo bolla
t > 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
gt; 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
py-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
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 > > _______ > Nump

Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
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.searchsort

Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
> 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
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/

Re: [Numpy-discussion] searchsorted bug

2008-01-31 Thread lorenzo bolla
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-

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 A

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

2008-01-30 Thread lorenzo bolla
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 Co

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) >

[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

[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 cropp

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

2008-01-09 Thread lorenzo bolla
aa ' , ' bb ', ' > cc '] > >>> vstrip(s) > array(['', '', ''], > dtype='|S8') > > where all strings are cropped to 8 characters.

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.dev45

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) -

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 PR

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(

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

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

2007-10-05 Thread lorenzo bolla
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]>: > > > > wha

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 PROTEC

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 > arra

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.0

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.

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 unzippe

[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/lis

[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 sett

[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

[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 n

[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.], dtyp

[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 (

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, dimensi

[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*/ DAT

[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. ___

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

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 "

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 i

Re: [Numpy-discussion] arctan2 with complex args

2007-04-29 Thread lorenzo bolla
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

[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 (mos

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

[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, t

Re: [Numpy-discussion] NumPy benchmark

2007-04-18 Thread lorenzo bolla
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

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 M

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

2007-03-14 Thread lorenzo bolla
nj() * 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?) q

[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] 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 "res

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

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: > > > &g

Re: [Numpy-discussion] reduction

2007-01-08 Thread lorenzo bolla
rris <[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 ( >

[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)