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?
CodePudding user response:
I am not sure if that will help but they are indeed separated by commas if you look at them in a jupyter notebook or execute them. But the print() method prints it differently (without the commas). And it has nothing to do with the mean function itself.
Like this:
>>> np.array([5, 5, 5])
Output:
array([5, 5, 5])
But with print:
>>> print(np.array([5, 5, 5]))
Output:
[5 5 5]
CodePudding user response:
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)) "]")