How to add comma between numbers in a numpy array?

Viewed 53

I'm wondering is there anyway to add a comma between numbers.

For example: [0.44346713 0.70174108 0.46043481 0.82511308 0.71445151]
to [0.44346713, 0.70174108, 0.46043481, 0.82511308, 0.71445151] in python

Thus, i can call each number in an array(e.g., list[0], list[2]...)

1 Answers

Your input is a numpy array:

import numpy as np

a = np.array([0.44346713, 0.70174108, 0.46043481, 0.82511308, 0.71445151])

print(a)
# [0.44346713 0.70174108 0.46043481 0.82511308 0.71445151]

Numpy has its built-in function of tolist():

print(a.tolist())
# [0.44346713, 0.70174108, 0.46043481, 0.82511308, 0.71445151]
Related