我想寫一個netcdf文件使用scipy。 我已經從scipy網站上覆制了這個例子 - 但是當我看着輸出時,我得到了奇怪的數字。scipy --netcdf - 數據類型不寫和得到奇怪的數字
我一直在嘗試其他的東西,甚至爲另一個我聲明爲'float32'的變量指定.astype(np.float32)。
Python代碼:
import numpy as np
from pylab import *
from scipy.io import netcdf
f = netcdf.netcdf_file('simple.nc', 'w')
f.history = 'Created for a test'
f.createDimension('time', 10)
time = f.createVariable('time', 'i', ('time',))
time[:] = np.arange(10)
time.units = 'days since 2008-01-01'
f.close()
輸出:
ncdump -v time simple.nc
netcdf simple {
dimensions:
time = 10 ;
variables:
int time(time) ;
time:units = "days since 2008-01-01" ;
// global attributes:
:history = "Created for a test" ;
data:
time = 0, 16777216, 33554432, 50331648, 67108864, 83886080, 100663296,
117440512, 134217728, 150994944 ;
}
什麼操作系統和你使用的是什麼版本的scipy?我無法在Ubuntu上重現此問題,scipy版本爲0.9.0或0.12.0。 – unutbu 2013-05-08 23:43:54
看來如果我使用'導入Scientific.IO.NetCDF作爲NetCDF'而不是'scipy.io import netcdf' - 我可以使用雙精度值並且得到合理的值。不知道它是否會在以後給我更多的數據類型問題。 – dianei 2013-05-09 13:51:04