**Problem :**

I am getting below error:

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

How can I fix it?

0 votes

This error "only length-1 arrays can be converted to Python scalars" is raised when the function expects a single value but you pass an array instead.

PFB code will solve your issue

import numpy as np import matplotlib.pyplot as plt def f(x): return np.int(x) f2 = np.vectorize(f) x = np.arange(1, 15.1, 0.1) plt.plot(x, f2(x)) plt.show()

You can skip the definition of f(x) and just pass np.int to the vectorize function: f2 = np.vectorize(np.int).