绘制两个numpy数组的元素乘积

时间:2017-09-30 05:40:39

标签: python arrays numpy matplotlib plot

我是python的新手,我想编写一个程序,将两个数组中存在的元素相乘并绘制图形 我该如何更正代码?

import matplotlib.pyplot as plt
import numpy as np
x=(np.double[0.1,0.001,0.0001,0.0001,0.00001])
y=(np.double[0.1,0.001,0.0001,0.0001,0.00001])
m=len(x)
n=len(y)

for m in range(0,m):
for n in range(0,n):
plt.plot[x(m),y(n)]

plt.show()

1 个答案:

答案 0 :(得分:1)

x = np.array([0.1, 0.001, 0.0001, 0.0001, 0.00001] )
plt.plot(x ** 2)
plt.show()

enter image description here

如果xy不同,请使用:

x = np.array([...]) # replace [...] with your list
y = np.array([...])
plt.plot(x * y)
plt.show()