Hi Burlen,
SWIG will generate a file named for example foo_wrap.c, which will
contains a call to import_array() inserted by SWIG because of the
%init %{
import_array();
%}
in the SWIG script.
So in the file foo_wrap.c (which will be compiled to a Python module
_foo.so), you should be able to
On Tue, 31 Jul 2012 14:48:24 -0600, Bill Spotz wfsp...@sandia.gov wrote:
Use %inline %{ ... %} around your function. SWIG will add your function
directly to the wrapper file as well as add a wrapper function for calling it
from python.
On Jul 31, 2012, at 2:04 PM, David Froger wrote
Hi,
I'm looking at SWIG/numpy tutorials
They are these tutorials:
http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html
http://www.scipy.org/Cookbook/SWIG_NumPy_examples
Reading numpy.i is also very instructive.
1- How do use apply for class functions %apply (bla) myobject::foo ?
I'm looking at SWIG/numpy tutorials
They are these tutorials:
http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html
http://www.scipy.org/Cookbook/SWIG_NumPy_examples
Sorry, I've read look for...
___
NumPy-Discussion mailing list
1- How do use apply for class functions %apply (bla) myobject::foo ?
%apply is specified on function/method arguments names and types
only,
never on function names. So if for example you use:
%apply (int* ARGOUT_ARRAY1, int DIM1) {(int* rangevec, int n)}
it will apply on every
I've been working on setting up a new buildbot for NumPy. Unfortunately, I
don't have much time to work on it, so it's slow going! Right now I am still
at
the stage of getting NumPy to pass all its tests on the machines I'm using as
test slaves. After that, I plan to transfer existing
Excerpts from Travis Oliphant's message of mar. mai 01 01:39:26 +0200 2012:
If you have particular reasons why we should choose a particular CI service,
please speak up and let your voice be heard. There is still time to make a
difference in what we are setting up.
Hi all,
What about
Excerpts from Sameer Grover's message of ven. mars 09 20:50:06 +0100 2012:
import gtk
import foo # where foo is any f2py-wrapped program
Subsequently, on exiting python interpreter, the interpreter crashes
with this error message - This application has requested the Runtime
to terminate it
Hi,
I think writing a Python script that convert your txt file to one netcdf file,
reading the txt file one line at a time, and then use the netcdf file normally
would be a good solution!
Best,
David
Excerpts from Chao YUE's message of mar. mars 20 13:33:56 +0100 2012:
Dear all,
I received
Excerpts from Xavier Barthelemy's message of mar. déc. 06 08:51:22 +0100 2011:
ok let me be more precise
I have an Z array which is the elevation
from this I extract a discrete array of Zero Crossing, and another discrete
array of Crests.
len(crest) is different than len(Xzeros). I have a
Excerpts from Xavier Barthelemy's message of mar. déc. 06 06:53:09 +0100 2011:
Hi everyone
I was wondering if there is a more optimal way to write what follows:
I am studying waves, so I have an array of wave crests positions, Xcrest
and the positions of the ZeroCrossings, Xzeros.
The
Thanks everybody for the different solutions proposed, I really appreciate.
What about this solution? So simple that I didn't think to it...
import numpy as np
from numpy import *
def f(arr):
return arr*2
a = array( [1,1,1] )
b = array( [2,2,2] )
c = array( [3,3,3] )
d = array( [4,4,4] )
Thank you Olivier and Robert for your replies!
Some remarks about the dictionnary solution:
from numpy import *
def f(arr):
return arr + 100.
arrs = {}
arrs['a'] = array( [1,1,1] )
arrs['b'] = array( [2,2,2] )
arrs['c'] = array( [3,3,3] )
arrs['d'] = array( [4,4,4] )
for key,value in
Hy everybody,
I'm wondering what is the (best) way to apply the same function to multiple
arrays.
For example, in the following code:
from numpy import *
def f(arr):
return arr*2
a = array( [1,1,1] )
b = array( [2,2,2] )
c = array( [3,3,3] )
d = array( [4,4,4] )
a = f(a)
b = f(b)
c =
Did you try loadtxt? I try to output something in the format 1.538D-06 with
Fortran in order to test reading it with loadtxt, but I always get
1.538E-06. Where does the 'D' come from?
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
program write_txt
real(kind=8):: x
open(10,file='data.txt')
do i = 1,10
x = i*2.
write(10,fmt='(2(D12.3))') x,x**2
enddo
close(10)
end program write_txt
In [1]: x,y = loadtxt('data.txt',unpack=True)
---
program write_txt
real(kind=8):: x
open(10,file='data.txt')
do i = 1,10
x = i*2.
write(10,fmt='(2(D12.3))') x,x**2
enddo
close(10)
end program write_txt
In [1]: def expDtofloat(s):
...: return float(s.replace('D','E'))
...:
In [2]: x,y =
Hy all,
As a test case before writing something bigger, I'm trying to write a little
Fortran module to compute the average of a array in these 4 cases:
avg2d_float, avg2d_double
avg3d_float, avg3d_double
I want this module to be callable from both Fortran and Python, using f2py.
4 Fortran
convenient for people who have to read unformatted binary fortran file very
often.
2009/5/28 David Froger david.froger.i...@gmail.com
Sorry, I still don't understand how to use FortranFile ...
The fortran code
program writeArray
implicit none
integer,parameter:: nx=2,ny
Thank you very much :-)
2009/5/28 Neil Martinsen-Burrell n...@wartburg.edu
On 2009-05-28 09:32 , David Froger wrote:
Hy Neil Martinsen-Burrell,
I'm trying the FortranFile class,
http://www.scipy.org/Cookbook/FortranIO/FortranFile
It looks like there are some bug in the last revision (7
/redone/file2/froger/travail/codes/lib/Tests/fortranread/fortranfile.py,
line 128, in readRecord
raise IOError('Could not read enough data')
IOError: Could not read enough dat
= How to read the file 'uxuyp.bin' ?
2009/5/28 David Froger david.froger.i...@gmail.com
Thank you very much
Thanks a lot Fransesc and Neil, yours messages really help me.
I'll look at these solutions attentively.
Here is what I write recently, but I begin to understand it's effectively
not portable...
def fread(fileObject,*arrayAttributs):
Reading in a binary (=unformatted) Fortran file
the last line was missing :
return arrays
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
idea to put the Fortran writting-arrays code and
the Python reading-array script in the cookbook and maybe a page to help
people comming from Fortran to start with Python ?
Best,
David Froger
program makeArray
implicit none
integer,parameter:: nx=10,ny=20
real(4),dimension(nx,ny):: ux,uy,p
Thank Sturla and Christopher,
yes, with the Fortran code :
!=
program makeArray
implicit none
integer,parameter:: nx=2,ny=5
real(4),dimension(nx,ny):: ux,uy,p
integer :: i,j
open(11,file='uxuyp.bin',form='unformatted')
do i = 1,nx
do j = 1,ny
ok for f2py!
Otherwise, you will have to figure out how your Fortran program writes the
file. I.e. what padding, metainformation, etc. that are used. If you
switch Fortran compiler, or even compiler version from the same vendor,
you must start over again.
In my experience, I never had this kind
Hello,
Here is a exemple of call-back use from Fortran to Python using f2py :
http://cens.ioc.ee/projects/f2py2e/usersguide/f2py_usersguide.pdf
But maybe you have already read it?
http://cens.ioc.ee/projects/f2py2e/usersguide/f2py_usersguide.pdf
2008/11/12 Dave Lang [EMAIL PROTECTED]
27 matches
Mail list logo