0
:http://earthpy.org/speed.html我發現下面的如何在這個環節上使用用Cython編譯器在Python
%%cython
import numpy as np
def useless_cython(year):
# define types of variables
cdef int i, j, n
cdef double a_cum
from netCDF4 import Dataset
f = Dataset('air.sig995.'+year+'.nc')
a = f.variables['air'][:]
a_cum = 0.
for i in range(a.shape[0]):
for j in range(a.shape[1]):
for n in range(a.shape[2]):
#here we have to convert numpy value to simple float
a_cum = a_cum+float(a[i,j,n])
# since a_cum is not numpy variable anymore,
# we introduce new variable d in order to save
# data to the file easily
d = np.array(a_cum)
d.tofile(year+'.bin')
print(year)
return d
這似乎是那麼容易,因爲只寫了功能%%用Cython。然而,這只是對我無效 - 「」聲明似乎沒有效果「,我的IDE說。 經過一些研究後,我發現%%語法來自我也安裝的iphyton(以及cython)。仍然沒有工作。 Iam使用python3.6 任何想法?