'Python: How to convert matrix to ASCII string? [closed]

I wanna ask about how to convert matrix to string then convert to text?
For example I have matrices from image and have range from 0 - 255:

[[224 65 90]  
[62 125 33]  
[75 40 94]]

I want the output is convert all matrix value to ASCII text with string type like this:

'àAZ>}!K(^'

The code:

slices = Image.Image.split(image)
channel_red = np.array(slices[0])

# Matrix to string code below
???


Solution 1:[1]

Here is a way to do what you asked:

import numpy as np
m=np.array([[224, 65, 90],
[62 ,125 ,33],
[75 ,40 ,94]])
print(''.join(map(chr,m.flatten())))

Updated based on rioV8's comment - no need for a list after join.

Output:

Out[34]: 'àAZ>}!K(^'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1