How to show numpy array as the desired result?

Joined
Dec 15, 2025
Messages
1
Reaction score
0
I have issue with this code.

Code:
import numpy


info = numpy.zeros((4,4))
info = numpy.array([[ 1,  2,  3,  4],  [2,  4,  6,  8], [ 3, 6, 9, 12], [4, 8, 12, 16]])


info2 = info.tolist()
print(info2)
 
for rivi in info2:
  for sarakke in rivi:
     print(sarakke, end=" ")
   print()

This code will print the following output.
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16


But I want that the code prints like this output.
1;2;3;4;
2;4;6;8;
3;6;9;12;
4;8;12;16;


Can someone help me?
 
Joined
Sep 20, 2022
Messages
338
Reaction score
42
I read a Python book once, here's my guess.
Code:
for rivi in info2:
  for sarakke in rivi:
     print(sarakke, end="")
     print(";", end="")
  print()
It works on tio.run.
Personally I dislike Python because even simple things look cryptic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top