I want to print a string depending on the values in a NumPy array, e.g. value 0 should lead to letter 'a'.
import numpy as np
arr = np.zeros((2,2))
arr[(0,0)] = 1
arr[(0,1)] = 2
printValues = {0:'a', 1:'b', 2:'c'}
print(np.array2string(arr, formatter={'str':lambda x: printValues[x]}))
Expected result:
[['b' 'c']
['a' 'a']]
Observed:
[[1. 2.]
[0. 0.]]