小编pet*_*nya的帖子

可分配数组的f2py错误

我有一个Fortran子程序,我想在Python中使用.

subroutine create_hist(a, n, dr, bins, hist)
    integer, intent(in) :: n
    real(8), intent(in) :: a(n)
    real(8), intent(in) :: dr
    integer, intent(out), allocatable :: hist(:)
    real(8), intent(out), allocatable :: bins(:)

    n_b = n_bins(a, n, dr)  ! a function calculating the number of bins
    allocate(bins(n_b+1))
    allocate(hist(n_b))
    hist = 0

    !... Create the histogram hist by putting elems of a into bins
end subroutine
Run Code Online (Sandbox Code Playgroud)

这是一个简单的程序,用于获取数字数组a并根据给定的bin大小创建直方图dr.首先,它得到使用功能窗口的数量n_bins,然后相应地分配用于阵列中的空间binshist.

虽然gfortran编译此代码很好,但f2py会引发错误:

/tmp/tmpY5badz/src.linux-x86_64-2.6/mat_ops-f2pywrappers2.f90:32.37:
      call create_hist_gnu(a, …
Run Code Online (Sandbox Code Playgroud)

python fortran f2py

7
推荐指数
2
解决办法
1601
查看次数

matplotlib imshow -- 使用任何向量作为轴

我想使用任何向量作为plt.imshow().

A = np.random.rand(4, 4)
x = np.array([1, 2, 3, 8])
y = np.array([-1, 0, 2, 3])
Run Code Online (Sandbox Code Playgroud)

我想象这样的事情:

plt.imshow(a, x_ax=x, y_ax=y)
Run Code Online (Sandbox Code Playgroud)

我知道有一个extent可用的参数,但遗憾的是它不允许非等距向量。

有人可以帮忙吗?提前致谢。

python matplotlib imshow

5
推荐指数
1
解决办法
5813
查看次数

标签 统计

python ×2

f2py ×1

fortran ×1

imshow ×1

matplotlib ×1