datatype强制性改变,提示TypeError: only length-1 arrays can be converted to Python scalars

参考自stackoverflow上的答案

1 import numpy as np
2 import matplotlib.pyplot as plt
3 
4 def f(x):
5     return np.int(x)
6 f2 = np.vectorize(f)#让函数矩阵化,解决只能一对一强制性变换这一要求
7 x = np.arange(1, 15.1, 0.1)
8 plt.plot(x, f2(x))
9 plt.show()

 

posted @ 2017-09-29 10:07  难解是非题  阅读(14773)  评论(0编辑  收藏  举报