Indices in Arrays werden anders als erwartet durchlaufen, warum?
Verfasst: Sonntag 24. März 2019, 17:08
Hallo!
Warum bringt der Code
ein für mich unerwartetes Ergebnis. Die Indices im Ergebnis, entsprechen nicht der Anordnung in den Angaben.
Was muss ich wissen, um solche Irrtümer zu vermeiden?
Mit einer für mich brauchbaren Kodierung In python:
Warum bringt der Code
Code: Alles auswählen
toarrV1 = np.array( [
... fromarr[:,:,0] * 100 + 1,
... fromarr[:,:,1] * 10000 + 2,
... ] )
Was muss ich wissen, um solche Irrtümer zu vermeiden?
Mit einer für mich brauchbaren Kodierung In python:
Code: Alles auswählen
>>> import numpy as np
>>> fromarr = np.array( [ \
... [ \
... [ 0, 1], \
... [ 2, 3] \
... ], \
... [ \
... [ 4, 5], \
... [ 6, 7] \
... ] \
... ])
>>> fromarr
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> toarrV1 = np.array( [
... fromarr[:,:,0] * 100 + 1,
... fromarr[:,:,1] * 10000 + 2,
... ] )
>>> toarrV1
array([[[ 1, 201],
[ 401, 601]],
[[10002, 30002],
[50002, 70002]]])
>>>
>>> # so funktioniert es für mich:
...
>>> toarrV2 = np.empty_like(fromarr, dtype = np.int )
>>> toarrV2[:,:,0] = fromarr[:,:,0] * 100 + 1
>>> toarrV2[:,:,1] = fromarr[:,:,1] * 10000 + 2
>>> toarrV2
array([[[ 1, 10002],
[ 201, 30002]],
[[ 401, 50002],
[ 601, 70002]]])