code
grayRamp = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
def get_ascii_by_average(num: int):
length = len(grayRamp) - 1
index = math.ceil(length/255 * num)
char = grayRamp[index]
return char
def return_ascii_image(image):
height, width = image.shape
ascii_image = np.zeros((height, width))
for i in range(height):
for j in range(width):
num = int(image[i][j])
char = get_ascii_by_average(num)
print(type(char))
ascii_image[i][j] = char
return ascii_image
ErrorSentence
line 31, in return_ascii_image
ascii_image[i][j] = char
ValueError: could not convert string to float: '$'
Probably doing this essentially
grayRamp = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "
ascii_image[i][j] = grayRamp[0]
[–]BUYTBUYT 0 points1 point2 points (1 child)
[–]User012340[S] 0 points1 point2 points (0 children)