0

Numpy.ndarray loop

I have numpyyy.ndarray a=([[1, 2, 3], [4, 5, 6],[7, 8, 9]]) and I want to print it like this 1 4. 7 2 5. 9 3 6 9 How can I do that in a loop? And how can I use the same approach to print an array but with a 1000 index's not only three?

2nd Jun 2021, 8:35 PM
Karzan
7 odpowiedzi
+ 2
for t in zip (*a): print (*t)
3rd Jun 2021, 1:48 AM
Vitaly Sokol
Vitaly Sokol - avatar
0
Hi Karzan What you’ll need it too while loops like this While x < a.length #get index of number Inside this add another array While z < a.length print(a[z][x]) You’ll need to change some of in python
2nd Jun 2021, 8:57 PM
Ollie Q
Ollie Q - avatar
0
for c in range(len(a[0])): for r in range(len(a)): print(a[r][c],end=" ") print()
2nd Jun 2021, 9:04 PM
visph
visph - avatar
0
Ollie Q what is the value of z?
2nd Jun 2021, 9:06 PM
Karzan
0
Ollie Q can you share your answer in an example?
2nd Jun 2021, 9:09 PM
Karzan
0
Here you go… Sorry the other one was a bit hard to understand https://code.sololearn.com/c1B4nVwussY9/?ref=app
2nd Jun 2021, 9:57 PM
Ollie Q
Ollie Q - avatar
- 1
X can start from zero but what about z?
2nd Jun 2021, 9:07 PM
Karzan