-1
votes

Comment itérer ce réseau dimensionnel?

Mon programme Imprimer comme

# more than one dimensions 
import numpy as np 
a = np.array([[[1,2,3], [3,4,5]],[[10,5,12], [13,6,14]]]) 
print a.shape
for k in a:
    for i in k:
        for j in i:
            print j


1 commentaires

Que diriez-vous de simplement imprimer (a) ?


3 Réponses :


1
votes

Le module pprint est effectué exactement pour ce genre d'objet.

utilisé comme ceci: xxx

Vous obtiendriez cette sortie: xxx


0 commentaires

2
votes
In [66]: block = [] 
    ...: for panel in a: 
    ...:     sub = [] 
    ...:     for row in panel: 
    ...:         sub.append(str(row)) 
    ...:     sub = '\n'.join(sub) 
    ...:     block.append(sub) 
    ...: block = '\n\n'.join(block)                                             
In [67]: block                                                                  
Out[67]: '[1 2 3]\n[3 4 5]\n\n[10  5 12]\n[13  6 14]'
In [68]: print(block)                                                           
[1 2 3]
[3 4 5]

[10  5 12]
[13  6 14]

0 commentaires

-1
votes

récursivement, vous pouvez le faire comme ceci: xxx

fonctions de test: xxx


0 commentaires