Wenden Sie 1D-Maske auf Numpy 3D-Array anPython

Python-Programme
Anonymous
 Wenden Sie 1D-Maske auf Numpy 3D-Array an

Post by Anonymous »

Ich habe das folgende 3D-

Code: Select all

numpy.ndarray
:

Code: Select all

import numpy as np
X = np.array([
[[0.0, 0.4, 0.6, 0.0, 0.0],
[0.6, 0.0, 0.0, 0.0, 0.0],
[0.4, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.6, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.4, 0.0, 1.0]],
[[0.1, 0.5, 0.4, 0.0, 0.0],
[0.6, 0.0, 0.0, 0.0, 0.0],
[0.2, 0.0, 0.0, 0.0, 0.0],
[0.1, 0.6, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.4, 0.0, 1.0]]
])
< /code>
Ich möchte ein Neues Array, in dem alle Zeilen und Spalten fallen gelassen werden, wo die Diagnone gleich 1. < /p>
istidx = np.diag(X[0]) == 1          # for my implementation it is sufficient to look at X[0]
Es ist wichtig zu beachten, dass X.Shape [1] == X.Shape [2] , daher versuche ich, die Maske wie folgt zu verwenden,

Code: Select all

Y = X[:, ~idx, ~idx]
< /code>
Das obige gibt etwas anderes zurück als meine gewünschte Ausgabe: < /p>

 [[0.0, 0.4, 0.6],
[0.6, 0.0, 0.0],
[0.4, 0.0, 0.0]],
[[0.1, 0.5, 0.4],
[0.6, 0.0, 0.0],
[0.2, 0.0, 0.0]]
Bitte rat Rating

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post