f2py::演示Fortran二维数组在python中的使用示例
2012-03-21 13:15
896 查看
f2py中二维数组的示例:
在DOS窗口输入
下面演示在python中如何使用:
详细介绍可见下面的网站
http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#string-arguments
C FILE: ARRAY.F SUBROUTINE FOO(A,N,M) C C INCREMENT THE FIRST ROW AND DECREMENT THE FIRST COLUMN OF A C INTEGER N,M,I,J REAL*8 A(N,M) Cf2py intent(in,out,copy) a Cf2py integer intent(hide),depend(a) :: n=shape(a,0), m=shape(a,1) DO J=1,M A(1,J) = A(1,J) + 1D0 ENDDO DO I=1,N A(I,1) = A(I,1) - 1D0 ENDDO END C END OF FILE ARRAY.F
在DOS窗口输入
f2py -c -m arr array.f
下面演示在python中如何使用:
>>> import arr >>> from Numeric import array >>> print arr.foo.__doc__ foo - Function signature: a = foo(a,[overwrite_a]) Required arguments: a : input rank-2 array('d') with bounds (n,m) Optional arguments: overwrite_a := 0 input int Return objects: a : rank-2 array('d') with bounds (n,m) >>> a=arr.foo([[1,2,3], ... [4,5,6]]) copied an array using PyArray_CopyFromObject: size=6, elsize=8 >>> print a [[ 1. 3. 4.] [ 3. 5. 6.]] >>> a.iscontiguous(), arr.has_column_major_storage(a) (0, 1) >>> b=arr.foo(a) # even if a is proper-contiguous ... # and has proper type, a copy is made ... # forced by intent(copy) attribute ... # to preserve its original contents ... copied an array using copy_ND_array: size=6, elsize=8 >>> print a [[ 1. 3. 4.] [ 3. 5. 6.]] >>> print b [[ 1. 4. 5.] [ 2. 5. 6.]] >>> b=arr.foo(a,overwrite_a=1) # a is passed directly to Fortran ... # routine and its contents is discarded ... >>> print a [[ 1. 4. 5.] [ 2. 5. 6.]] >>> print b [[ 1. 4. 5.] [ 2. 5. 6.]] >>> a is b # a and b are acctually the same objects 1 >>> print arr.foo([1,2,3]) # different rank arrays are allowed copied an array using PyArray_CopyFromObject: size=3, elsize=8 [ 1. 1. 2.] >>> print arr.foo([[[1],[2],[3]]]) copied an array using PyArray_CopyFromObject: size=3, elsize=8 [ [[ 1.] [ 3.] [ 4.]]] >>> >>> # Creating arrays with column major data storage order: ... >>> s = arr.as_column_major_storage(array([[1,2,3],[4,5,6]])) copied an array using copy_ND_array: size=6, elsize=4 >>> arr.has_column_major_storage(s) 1 >>> print s [[1 2 3] [4 5 6]] >>> s2 = arr.as_column_major_storage(s) >>> s2 is s # an array with column major storage order # is returned immediately 1
详细介绍可见下面的网站
http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#string-arguments
相关文章推荐
- f2py::演示在python中如何使用Fortran代码
- f2py::演示Fortran中的公用区在Python中的使用
- Python使用分布式锁的代码演示示例
- f2py::演示Fortran字符串在python中的用法
- Python爬虫之pandas基本安装与使用方法示例
- Python urlopen 使用小示例
- python使用ctypes模块调用windowsapi获取系统版本示例
- python使用新浪微博api上传图片到微博示例
- 使用minidom来处理XML的示例(Python 学习)(转载)
- Python多进程multiprocessing使用示例
- Python使用re模块正则提取字符串中括号内的内容示例
- [UIA]Python使用UIA基本示例
- python使用ctypes模块调用windowsapi获取系统版本示例
- 使用Python脚本来获取Cisco设备信息的示例
- 在Python中使用AOP实现Redis缓存示例
- Python中使用ElementTree解析XML示例
- CGI介绍及使用Python来开发CGI应用示例
- linux使用tcpdump抓包工具抓取网络数据包,多示例演示
- Linux 常用命令解析和Bash Shell使用示例脚本演示
- Python队列的定义与使用方法示例