Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mean function output not separated by commas

That’s my code:

array = np.array([[0,1,2],[3,4,5],[6,7,8]])
axis1_mean = np.mean(array,axis = 0)
print(axis1_mean)

That’s the output:

[3. 4. 5.]

I need the output separated by commas, is there an easy way to do so?
I found in the documentation of Numpy that the output should be separated by commas. Does anyone see what I’m missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to separate the CONTENT of your data from the REPRESENTATION of your data. Your data is a list of three floating point numbers. There are no commas, no brackets, and no decimal points in your data.

If you need to PRESENT your data in a specific way, then it is up to you to do that. What you’re seeing is the way numpy presents data by default. If you want commas, you have to add them:

print( "[" + (",".join(str(f) for f in axis1_mean)) + "]")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading