Ciao a tutti, sto cercando di capire come "accatastare" array numpy bidimensionali per formare un array numpy tri-dimensionale.
qui: http://docs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html#numpy.dstack dice "Takes a sequence of arrays and stack them along the third axis to make a single array", che è quello che voglio ottenere.... ...ma poi aggiunge: "Arrays to stack. All of them must have the same shape along all but the third axis." ed i miei numpy array bidimensionali sono di dimensioni diverse. Esempio: >>> a = np.array((1,2,3)) >>> b = np.array((2,3,4)) >>> np.shape(a) (3,) >>> np.shape(b) (3,) >>> np.dstack((a,b)) array([[[1, 2], [2, 3], [3, 4]]]) >>> np.shape(np.dstack((a,b))) (1, 3, 2) >>> c = np.array([[1,2],[3,4]]) >>> d = np.array([[5,6],[7,8],[9,10]]) >>> np.shape(c) (2, 2) >>> np.shape(d) (3, 2) il mio obiettivo è avere un numpy array tri-dimensionale del tipo: >>> obiettivo = np.array([[[1,2],[3,4]], [[5,6],[7,8],[9,10]]]) >>> np.shape(obiettivo) (2,) >>> obiettivo[0] [[1, 2], [3, 4]] >>> obiettivo[1] [[5, 6], [7, 8], [9, 10]] >>> np.shape(obiettivo[1]) (3, 2) >>> np.shape(obiettivo[0]) (2, 2) Il problema è che, non so per quale motivo, il dtype diventa 'object': >>> obiettivo array([[[1, 2], [3, 4]], [[5, 6], [7, 8], [9, 10]]], dtype=object) C'è un modo per ottenere un array numpy tri-dimensionale(z,x,y) a partire da numpy array bidimensionali(x,y) con y variabile, mantenendo lo stesso dtype dei numpy array bidimensionali iniziali? Marco _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python