TypeError: only size-1 arrays can be converted to Python scalars (matplotlib)

This error occurs when you’re trying to cast into an integer something that isn’t just one scalar. For instance, a ndarray with two elements. This is an example of this error:

import numpy as np

int(np.array([1, 3]))

TypeError: only size-1 arrays can be converted to Python scalars

What you can do is use .astype(int)

(mm/square_size).astype(int)

Leave a Comment