How can I convert a module to a list or an array before plotting?

Viewed 47

I have 2 files in PyCharm:

parable.py:

def function_parable(a):

    return [x**2 for x in a]

main.py:

import numpy as np
import matplotlib.pyplot as plt
a = [1, 2, 3, 4, 5]
a = np.array(a)
n = a.shape
print(n)
print(type(a))
print(a)

import parable as b
print(b.function_parable(a))
print(type(b))


plt.plot(a,b)
plt.show()

Error: ValueError: x and y must have same first dimension, but have shapes (5,) and (1,)

How can I maintain this structure and solve this problem? Thanks!

1 Answers

try the following script:

import numpy as np
import matplotlib.pyplot as plt
a = [1, 2, 3, 4, 5]
a = np.array(a)
n = a.shape
print(n)
print(type(a))
print(a)

import parable as f
b = f.function_parable(a)
print(b)
print(type(b))


plt.plot(a,b)
plt.show()

Happy coding my friend.

Related