I have a NumPy array with a shape of (100,3). If I try to print the array, it looks like this:
[[ 0 8 10]
[ 1 29 10]
[ 3 29 6]
...
[ 2 9 5]
[ 2 10 5]
[ 2 26 10]]
I want to convert the array to a string, but with this format:
(0,8,10),(1,29,10),(3,29,6)...
That way I could set the array like so:
nparray = np.array([InsertStringHere])
How would I do this?
>Solution :
Try this:
import numpy as np
array = np.array([[0, 8, 10],
[1, 29, 10],
[3, 29, 6],
[2, 9, 5],
[2, 10, 5],
[2, 26, 10]])
string_array = ",".join([str(tuple(row)) for row in array])
print(string_array)