Re: [Numpy-discussion] Long-standing issue with using numpy in embedded CPython

2011-12-10 Thread Vicente Sole
Hi Peter,

The obsolete link was not deliberate. It was the first reference I  
found via google.

Best regards,

Armando

Quoting Peter CYC :

> Hi Armando,
>
> No comment on the Java thing ;-)
>
> However,   
> http://www.opengda.org/documentation/manuals/Diamond_SciSoft_Python_Guide/8.18/contents.html
> is more up-to-date and we are on github too:
> https://github.com/DiamondLightSource
>
> Peter
>
>
> On 9 December 2011 13:05, Vicente Sole  wrote:
>> Quoting Robert Kern :
>>
>>> On Fri, Dec 9, 2011 at 11:00, Yang Zhang  wrote:
>>>
>>>> Thanks for the clarification.  Alas.  So is there no simple workaround
>>>> to making numpy work in environments such as Jepp?
>>>
>>> I don't think so, no.
>>>
>>
>> It is far from being an optimal solution (in fact I dislike it) but
>> there is a couple of research facilities that like the python
>> interpreter, they like numpy, but prefer to use java for all their
>> graphical interfaces. They have rewritten part of numpy in java in
>> order to use it from Jython.
>>
>> http://www.opengda.org/documentation/manuals/Diamond_SciSoft_Python_Guide/8.16/scisoftpy.html
>>
>>
>> Armando
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Long-standing issue with using numpy in embedded CPython

2011-12-09 Thread Vicente Sole
Quoting Robert Kern :

> On Fri, Dec 9, 2011 at 11:00, Yang Zhang  wrote:
>
>> Thanks for the clarification.  Alas.  So is there no simple workaround
>> to making numpy work in environments such as Jepp?
>
> I don't think so, no.
>

It is far from being an optimal solution (in fact I dislike it) but  
there is a couple of research facilities that like the python  
interpreter, they like numpy, but prefer to use java for all their  
graphical interfaces. They have rewritten part of numpy in java in  
order to use it from Jython.

http://www.opengda.org/documentation/manuals/Diamond_SciSoft_Python_Guide/8.16/scisoftpy.html


Armando
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] what python module to modify NetCDF data?

2011-10-08 Thread Vicente Sole
Hi,

I have never seen myself a NetCDF file but if your NetCDF file is  
using HDF5 as format (possible since NetCDF 4 if I am not mistaken),  
you should be able to use h5py or PyTables to access and or modify it.

Best regards,

Armando

Quoting Chao YUE :

> Dear all,
>
> I want to change some variable values in a series of NetCDF file. Did
> anybody else did this before using python?
> Now I use pupynere for reading data from NetCDF files and making plots. but
> the document of pupynere for writing data to NetCDF file is quite simple and
> I still feel difficult to do this with pupynere.
>
> the NetCDF file I want to change is a global data (0.5X0.5d resolution,
> 360X720grid with 12 time steps) and have approx. 10 variables. I just want
> to change some points for a specific
> variable for all 12 time steps. I know it's possible use NCO ncap2 utility
> to do the job. but now I have some problem in using ncap2 within a shell
> script.
> I guess there is some easy way to use some python module to do the job? like
> mainly altering the data that need to change while let the others remaining
> intact?
>
> Any idea will be greatly appreciated. I will all a good weekend,
>
> Chao
>
> --
> ***
> Chao YUE
> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
> UMR 1572 CEA-CNRS-UVSQ
> Batiment 712 - Pe 119
> 91191 GIF Sur YVETTE Cedex
> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
> 
>


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Simple problem. Is it possible without a loop?

2010-06-09 Thread Vicente Sole
Quoting josef.p...@gmail.com:

> but the two options don't produce the same result in general, the
> cumsum version doesn't restart from zero, I think
>
> try
> x0 = np.random.randint(5,size=30).cumsum()
> with delta=3
>
> I don't see a way around recursive looping
>

The x0 data are already sorted. It was one of the premises of the first post.

The solution I proposed makes "almost" what I need and I will most  
likely use it. It just misses the first value but takes the next one  
what is fine for my application. For the simple example, it returns  
[1, 5, 9] instead of [0, 4, 8] but it should not disturb me.

Armando

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Simple problem. Is it possible without a loop?

2010-06-09 Thread Vicente Sole
It gets even worse with data similar to those I will be using.

With:

x0 = numpy.linspace(-1,1, 1)
niter = 2000

I get 24 seconds for option1 and 0.64 seconds for option2.
Considering I expect between 5 and 50 times that number of iterations,  
the difference is already quite considerable.

Armando

Quoting Vicente Sole :

>>> ? Well a loop or list comparison seems like a good choice to me. It is
>>> much more obvious at the expense of two LOCs. Did you profile the two
>>> possibilities and are they actually performance-critical?
>>>
>>> cheers
>>>
>
>
> The second is between 8 and ten times faster on my machine.
>
> import numpy
> import time
> x0 = numpy.arange(1.)
> niter = 2000   # I expect between 1 and 10
>
>
> def option1(x, delta=0.2):
>  y = [x[0]]
>  for value in x:
>  if (value - y[-1]) > delta:
>  y.append(value)
>  return numpy.array(y)
>
> def option2(x, delta=0.2):
>  y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
>  i1 = numpy.nonzero(y[1:]>  y[:-1])
>  return numpy.take(x, i1)
>
>
> t0 = time.time()
> for i in range(niter):
>  t = option1(x0)
> print "Elapsed = ", time.time() - t0
> t0 = time.time()
> for i in range(niter):
>  t = option2(x0)
> print "Elapsed = ", time.time() - t0
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Simple problem. Is it possible without a loop?

2010-06-09 Thread Vicente Sole
>> ? Well a loop or list comparison seems like a good choice to me. It is
>> much more obvious at the expense of two LOCs. Did you profile the two
>> possibilities and are they actually performance-critical?
>>
>> cheers
>>


The second is between 8 and ten times faster on my machine.

import numpy
import time
x0 = numpy.arange(1.)
niter = 2000   # I expect between 1 and 10


def option1(x, delta=0.2):
 y = [x[0]]
 for value in x:
 if (value - y[-1]) > delta:
 y.append(value)
 return numpy.array(y)

def option2(x, delta=0.2):
 y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
 i1 = numpy.nonzero(y[1:]>  y[:-1])
 return numpy.take(x, i1)


t0 = time.time()
for i in range(niter):
 t = option1(x0)
print "Elapsed = ", time.time() - t0
t0 = time.time()
for i in range(niter):
 t = option2(x0)
print "Elapsed = ", time.time() - t0

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Simple problem. Is it possible without a loop?

2010-06-09 Thread Vicente Sole
Correct. I thought just multiplying by -1 and inverting the logical  
condition would give me the same output.

This makes exactly what I want:

>>> x= numpy.arange(10.)
>>> delta=3
>>> y=[x[0]]
>>> for value in x:
> ... if (value-y[-1]) < delta:
> ...y.append(value)
> ...
>>> y
[0., 4., 8.]


Armando

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Matrix operation.

2010-04-02 Thread Vicente Sole
With A and X being arrays:

B=numpy.zeros(A.shape, A.dtype)
B[A>0] = X

Armando


Quoting gerardob :

>
> Let A be a square matrix of 0's and 1's, and let X be a one dimesional
> vector.
> The length of X is equal to the number of 1's that A has.
> I would like to produce a new matrix B by traversing the matrix A row by row
> and:
> 1- whenever i find a 0, set B in that position to zero.
> 2- whenever i find a 1, set B in that position with the ith value of X
> (where i represents the ith time i found a 1).
>
> Example.
> input:
> A=[[1,1,0],
> [1,0,0],
> [0,0,1]]
>
> X=[2,9,10,3]
>
> Output:
> B =[[2,9,0],
>[10,0,0],
>[0,0,3]]
>
> Which is an efficient way to accomplish this using numpy?
>
> Thanks.
> --
> View this message in context:   
> http://old.nabble.com/Matrix-operation.-tp28119663p28119663.html
> Sent from the Numpy-discussion mailing list archive at Nabble.com.
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] performance matrix multiplication vs. matlab

2010-01-18 Thread Vicente Sole
Quoting Bruce Southey :

> On 01/18/2010 12:47 PM, Vicente Sole wrote:
>> Quoting Bruce Southey :
>>
>>>
>>> If you obtain the code from any package then you are bound by the terms
>>> of that code. So while a user might not be 'inconvenienced' by the LGPL,
>>> they are required to meet the terms as required. For some licenses (like
>>> the LGPL) these terms do not really apply until you distribute the code
>>> but that does not mean that the user is exempt from the licensing terms
>>> of that code because they have not distributed their code (yet).
>>>
>>> Furthermore there are a number of numpy users that download the numpy
>>> project for further distribution such as Enthought, packagers for Linux
>>> distributions and developers of projects like Python(x,y). Some of these
>>> users would be inconvenienced because binary-only distributions would
>>> not be permitted in any form.
>>>
>>
>> I think people are confusing LGPL and GPL...
> Not at all.
>
>>
>> I can distribute my code in binary form without any restriction   
>> when using an LGPL library UNLESS I have modified the library itself.
>
> I do not interpret the LGPL version 3 in this way:
> A "Combined Work" is a work produced by combining or linking an
> Application with the Library.
> So you must apply section 4, in particular, provide the "Minimal
> Corresponding Source":
> The "Minimal Corresponding Source" for a Combined Work means the
> Corresponding Source for the Combined Work, excluding any source code
> for portions of the Combined Work that, considered in isolation, are
> based on the Application, and not on the Linked Version.
>
> So a binary-only is usually not appropriate.
>

You are taking point 4.d)0 while I am taking 4.d)1:

"""
1) Use a suitable shared library mechanism for linking with the  
Library. A suitable mechanism is one that (a) uses at run time a copy  
of the Library already present on the user's computer system, and (b)  
will operate properly with a modified version of the Library that is  
interface-compatible with the Linked Version.
"""

If you are using the library as a shared library (what you do most of  
the times in Python), you are quite free.

In any case, it seems I am not the only one seeing it like that:

http://qt.nokia.com/downloads

The key point is if you use the library "as is" or you have modified it.

Armando
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion