[英]How to plot a 3d surface from multiple 2d arrays and one 1d array?
[英]Python - Joining multiple 2D arrays into one 3D array
所以我有多個文件可以訪問並被視為 2D arrays。我想做的是將所有這些 2D arrays 放入一個 3D 數組中。 例如,如果我有 10 個形狀為 (100,100) 的文件,當我組合它們時,應該留下形狀為 (10,100,100) 的 3D 數組。 我的以下嘗試如下:
filenames = glob.glob('source')
preset = np.empty([100,100], dtype = 'int16')
for file in filenames:
data = fits.open(file)[0].data
np.vstack([preset,data]).reshape((10,100,100))
但我得到的是以下錯誤:
ValueError: cannot reshape array of size 20000 into shape (10,100,100)
您正在成對執行操作。 嘗試對所有 arrays 一起執行此操作:
arrs = [fits.open(file)[0].data for file in filenames]
np.vstack(arrs).reshape((10,100,100))
或者更直接:
np.stack(arrs)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.