【问题标题】:Issue in plotting array in python在 python 中绘制数组的问题
【发布时间】:2020-04-30 15:57:25
【问题描述】:

TypeError:只有 size-1 的数组可以转换为 Python 标量

import math
import numpy as np
import matplotlib.pyplot as plt
def myfunction(x):
    return np.int(x)
myfunction2 = np.vectorize(myfunction)
x = np.array([0, math.pi/100, 2*math.pi])
y = math.sin(x)
plt.plot(myfunction2(x),y)
plt.show()

【问题讨论】:

标签: python


【解决方案1】:

我看到了一些问题。首先,您需要使用np.sin 才能将其应用于整个向量。其次,您对 x 的定义只有 3 个元素长。我相信您正在尝试使用np.arange。请改用x = np.arange(0,2*math.pi,math.pi/100,dtype='float32')

【讨论】:

    猜你喜欢
    • 2020-09-03
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 2013-07-02
    • 2020-07-28
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    相关资源
    最近更新 更多