python数组合并、输入三行数据,如何在python中合并两个或三个3D数组?
Numpy的hstack、vstack或dstack(取決于要連接數組的軸)將連接多維數組。在
請注意,對于MODIS氣溶膠數據,使用hstack連接陣列有時會拋出錯誤,因為有時陣列是203 x 135,有時是204 x 135,因此水平維度并不總是匹配的
基于您的代碼構建(不漂亮,但功能強大):import glob
import numpy as np
import os
from pyhdf.SD import SD,SDC
files = glob.glob('MOD04*')
files.sort()
for n, f in enumerate(files):
product = f[0:5]+ '-Atmospheric Product'
year = f[10:14]
jdn = f[14:17] # julian day number
# Read dataset.
hdf = SD(f, SDC.READ)
data3D = hdf.select('Deep_Blue_Aerosol_Optical_Depth_550_Land')
data = data3D[:,:].astype(np.double)
# Read geolocation dataset
lat = hdf.select('Latitude')
latitude = lat[:,:]
lon = hdf.select('Longitude')
longitude = lon[:,:]
if n != 0 and jdn != old_jdn:
#do analysis; write to file for later analysis; etc.
pass
if n == 0 or jdn != old_jdn:
data_timeseries = data
latitude_timeseries = latitude
longitude_timeseries = longitude
else:
data_timeseries = np.vstack((data_timeseries, data))
latitude_timeseries = np.vstack((latitude_timeseries, latitude))
longitude_timeseries = np.vstack((longitude_timeseries, longitude))
print data_timeseries.shape
print latitude_timeseries.shape
print longitude_timeseries.shape
old_jdn = jdn
總結
以上是生活随笔為你收集整理的python数组合并、输入三行数据,如何在python中合并两个或三个3D数组?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java9 基于异步响应式流的发布-订阅
- 下一篇: Qt 调用Python引擎混合编程