[英]Error: expected an indented block
Can someone explain why I am getting this error? 有人可以解释为什么我收到此错误吗?
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
datapath = r"C:\Users\matth\Downloads\MYD04_L2_v6.0_110E155E_045S010S.A2010_calcv2_dod_flg1.nc"
f = Dataset(datapath)
for i in range(0, 30):
dod = f.variables['dod_modis_flg1'][i]
dod[dod == 0] = np.nan
def nan_if(arr, value):
return np.where(arr == value, np.nan, arr)
mean = np.nanmean([nan_if(dod, -9.99)])
print(mean)
#print(np.nanmax(dod))
#print(np.nanmin([nan_if(dod, -9.99)]))
dod_high = dod[(dod > mean) & (dod != 0)]
anomalies = []
for val in dod_high:
if val > mean:
#print(anomalies)
dod_high_indices1 = np.where((dod > mean) & (dod != 0))
dod_high_indices2 = np.array(np.where((dod > mean) & (dod != 0))).T
anomalies_ind = []
for ind in dod_high_indices2:
anomalies_ind.append(ind)
print(np.asarray(anomalies_ind))
OUTPUT: 输出:
%run "C:/Users/matth/dod_anomalies.py"
File "C:\Users\matth\dod_anomalies.py", line 26
dod_high_indices1 = np.where((dod > mean) & (dod != 0))
^
IndentationError: expected an indented block
It seems to me that the indentation of my code is correct... for some reason, I keep on getting this error. 在我看来,我的代码缩进是正确的……出于某种原因,我不断收到此错误。
Python is expecting something after Python在期待之后
if val > mean:
It ignores the commented block. 它忽略注释的块。 If you have an empty if statement like that, just put in pass, so python knows that it is there.
如果您有一个空的if语句,则只需传递即可,因此python知道它在那里。
if val>mean:
#print(anomalies)
pass
An if
needs a body, and in if
需要身体,在
for val in dod_high:
if val > mean:
#print(anomalies)
a comment doesn't count. 评论不算在内。 You could make the body
pass
, or comment out the if
(or the whole loop), but in context, it seems like you might have more serious problems. 您可以使body
pass
,或注释掉if
(或整个循环),但是在上下文中,似乎您可能遇到了更严重的问题。 Even uncommented, that print
would only ever have printed []
. 即使没有注释,该
print
也只会打印[]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.