如何解决如何将数组转换为标量?类型错误:只有整数标量数组可以转换为标量索引
我已将 myfunction
从一个脚本调用到另一个脚本中。我的函数如下所示:
import numpy as np
from hypy import htj
def myfunction(transmissivity,S,t,headchange,rw,b_aquitard,K_aquitard):
tD = T * t / (rw**2 * S)
Lp = rw/np.sqrt(transmissivity *b_aquitard/K_aquitard)
for i in range(Lp):
W_leaky,_ = htj.dls_array(np.array([Lp]),tD)
myfunction = (headchange * transmissivity * t * 2 * np.pi) / W_leaky
return myfunction
htj.dls_array
函数是从另一个脚本调用的。 myfunction 运行正常,没有任何错误。
现在,我从脚本 myfunction
solving_functions
import numpy as np
from solving_functions import myfunction
import Rasterio
from Rasterio.plot import show
#### Parameters
rw = 0.15
t = 30
K_aquitard = 1e-4
b_aquitard = 10
S = 1e-3
#### Read raster files
transmissivity = Rasterio.open("D:/washingon county/rasters/Elmo_T_rev1_1.tif")
transmissivity_array = transmissivity.read(1)
headchange = Rasterio.open("D:/washingon county/rasters/qgis/head_change_85_5.tif")
headchange_array = eheadchange.read(1)
##### IC calculation
IC_leaky = myfunction(transmissivity_array,headchange_array,K_aquitard)
# ###### Convert and save array as raster
driver = "GTiff"
dim = IC_leaky.shape
height = dim[0]
width = dim[1]
count = 1
dtype = IC_leaky.dtype
crs = transmissivity.crs #### Projection system
transform = transmissivity.transform
with Rasterio.open("D:/washingon county/rasters/IC_leaky_test.tif","w",driver=driver,height=height,width=width,count=count,dtype=dtype,crs=crs,transform=transform) as dst:
dst.write(IC_leaky,indexes=1)
show(IC_leaky,title='IC leaky',cmap='Spectral')
File "E:\Python\Python_works\solving_functions.py",line 123,in myfunction
for i in range(Lp):
TypeError: only integer scalar arrays can be converted to a scalar index
我是 Python 的新手。我知道错误的来源,但我无法纠正它们。该错误可以通过在循环内调用函数 htj.dls_array
来解决,因为 Lp 是一个二维数组。
我将非常感谢更改行 for i in range(Lp):
和 W_leaky,tD)
以使其运行的任何直接帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。