harikrishnan harikrishnan - 3 years ago 244
Python Question

Plot the element-wise product of two numpy arrays

I'm very new to python, I wanted to write a program that multiplies elements present inside two arrays and plots a graph
How should I correct the code?

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()

Answer Source

I believe you're looking for this:

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

enter image description here


If x and y are different, use:

x = np.array([...]) # replace [...] with your list
y = np.array([...])
plt.plot(x * y)
plt.show()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download