I want to convert a numpy array to a string representation and I am having issues when the number of digits in the numpy array is not constant. Consider the two cases -
import numpy as np
arr = np.array([0,0])
arr_str = str(arr).strip("[]")
print("String:", arr_str)
print("Len:", len(arr_str))
arr = np.array([10,0])
arr_str = str(arr).strip("[]")
print("String:", arr_str)
print("Len:", len(arr_str))
The output from this is -
String: 0 0
Len: 3
String: 10 0
Len: 5
The first case has the two digits separated by a single space while the second one has two spaces. The length of the second string should have been 4 and not 5 if it wasn't for the extra space. Is there any way to convert numpy to string so that every element is consistently separated by a single space?
This was with python 3.8 and numpy 1.19.2