如何强制numpy的阵列以FORTRAN风格? [英] How to force numpy array order to fortran style?

查看:708
本文介绍了如何强制numpy的阵列以FORTRAN风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了很多Fortran库中做一些数学计算。因此,在numpy的需要所有的数组为的的Fortran连续的。结果
目前,我做到这一点与<一个href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.asfortranarray.html\">numpy.asfortranarray().

我的问题是:


  1. 这是告诉numpy的该数组应存放在FORTRAN风格或者是有一个更快的一个快速方法是什么?

  2. 有没有设置一些numpy的标志,使每个创建阵列在FORTRAN风格的可能性?


解决方案

使用可选的参数顺序='F'(默认为'C'),生成numpy.array对象时。这是我做的方式,可能确实,你正在做同样的事情。关于2号,我不知道设置默认顺序的,但它很容易不够的,只是为了包含可选的参数生成阵列时。

I am using quite a lot of fortran libraries to do some mathematical computation. So all the arrays in numpy need to be Fortran-contiguous.
Currently I accomplish this with numpy.asfortranarray().

My questions are:

  1. Is this a fast way of telling numpy that the array should be stored in fortran style or is there a faster one?
  2. Is there the possibility to set some numpy flag, so that every array that is created is in fortran style?

解决方案

Use optional argument order='F' (default 'C'), when generating numpy.array objects. This is the way I do it, probably does the same thing that you are doing. About number 2, I am not aware of setting default order, but it's easy enough to just include order optional argument when generating arrays.

这篇关于如何强制numpy的阵列以FORTRAN风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆