0
import numpy
import tables

file = tables.openFile( "....hdf5","r")
lon = numpy.array(file.root.lon)
lon.ravel()
lat = numpy.array(file.root.lat)
lat.ravel()
data = numpy.array(file.root.data)

v0= data.shape[0]
v1= data.shape[1]
v2= data.shape[2]
wind_spectrum_flat = data.reshape((v0, v1*v2))

interval_spectrum = numarray.arange(30) + 0.5
speed_mean = numarray.dot(interval_spectrum, wind_spectrum_flat)/days/24.
value = numarray.reshape(speed_mean, (v1, v2) )
value.ravel()

lat.shape、lon.shape、value.shape を出力

(480,640) (480,640) (307200,)

output = numpy.column_stack((lon,lat,value))

出力は次のようになります。

1.131087052608466621e+02   2.245298999778770010e+01   3.922619047619047450e+001.131096961042312046e+02   2.245299666446372910e+01 

各行に3つの数値(科学的ではない)列を取得するようにフォーマットするにはどうすればよいですか? すなわち:

11310870  224529 3.922
11310969  224529 4.512
11320485  223643 5.332
...
4

1 に答える 1

4

savetxt fmt キーワードを次のように使用できます。

numpy.savetxt(out_name,output, fmt="%u %u %.3f")

この方法で、ドットの前に 3 桁の 2 つの整数と 1 つの浮動小数点数を出力します。

各ベクトルが正しいベクトル形状 (1 次元配列) であることを確認するには、コード内で以下を置き換えることができます。

x = x.flat

に :

x.ravel()

ここで、x は経度、緯度、およびデータ ベクトルにすることができます。

于 2012-07-30T07:51:54.183 に答える