[f2py] status of numpy and character string arrays

ES eli-sava at pacbell.net
Wed Jan 3 03:05:54 EET 2007


Sorry about the html.

Eli:
Thanks so much for such a quick response! Is the third generation of 
f2py available, perhaps from a repository?

Your answer got me a lot closer and is easy for me to implement. I 
still get an error following your example. Is this something you 
recognize? Is it a numpy issue (I'm 0.9.9 and you are 1.0.1.dev3413)? 
Cheers -- Eli

C:\Delta\models\pydss>c:\Python24\python.exe test.py
Traceback (most recent call last):
   File "test.py", line 5, in ?
     mystring_new.foo2(a)
ValueError: data type must provide an itemsize



Pearu:
To get the same behaviour as with using Numeric, you must explicitly
create a numpy array of characters. Using your example:

 >>> import mystring_new
 >>> from numpy import array
 >>> a=array(('abcde','vwxyz'))
 >>> a
array(['abcde', 'vwxyz'],
       dtype='|S5')
 >>> mystring_new.foo2(a)
1-th dimension must be 5 but got 0 (not defined).
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
mystring_new.error: failed in converting 1st argument `a' of
mystring_new.foo2 to C/Fortran array
 >>> a=array(('abcde','vwxyz'),'c')
 >>> mystring_new.foo2(a)
  A(1)=abcde
  A(2)=vwxyz
 >>>

The support for numpy array of strings is implemented in the 3rd
generation of f2py.

Pearu










More information about the f2py-users mailing list