-2

I don't know much about coding and am trying to open a .py my boyfriend wrote for me. I finally got matploglib/seaborn/numpy to install but now I am getting this error and don't know what it means/how to remedy it:

AttributeError: module 'numpy' has no attribute 'cost'

numpy is updated with the latest version. I tried to look for the answer before posting this but couldn't find it. If anyone could help, that'd be sick.

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
t = np.arange(0,2*np.pi,0.1)
x = 16 * np.sin(t)**3
y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cost(3*t)-np.cos(4*t)
plt.plot(x,y)
sns.set_style("dark")
sns.despine()
plt.show()
FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
amt
  • 13
  • 4
  • 3
    Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – Aditi Feb 15 '18 at 13:54
  • 2
    can you post a snippet of the code? It should tell you what line is throwing the error and then we can see what you are trying to do. This seems like the code has "np.cost" but that isn't a real attribute or value inside numpy – lwileczek Feb 15 '18 at 13:55
  • line 7, in y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cost(3*t)-np.cos(4*t) AttributeError: module 'numpy' has no attribute 'cost' – amt Feb 15 '18 at 13:58
  • You should ask your boyfriend. LOL – Arpit Solanki Feb 15 '18 at 13:58
  • haha I would but he thinks I gave up trying to figure it out – amt Feb 15 '18 at 13:59
  • well it is saying "cost" is not a method which is true, there is probably a typo where there are no parenthesis you have y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cost(3*t)-np.cos(4*t) should be y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t). If you ever want to know what methods are available you can use doc(module) e.g. doc(numpy) – lwileczek Feb 15 '18 at 14:05
  • 2
    Do you know what the formula is supposed to look like: `y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cost(3*t)-np.cos(4*t)` it looks like a typo:`cost(3*t)->cos(3*t)` – FlyingTeller Feb 15 '18 at 14:05
  • `import matplotlib.pyplot as plt import numpy as np import seaborn as sns t = np.arange(0,2*np.pi,0.1) x = 16 * np.sin(t)**3 y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cost(3*t)-np.cos(4*t) plt.plot(x,y) sns.set_style("dark") sns.despine()` pretty sure it's just a heart or something. Also sorry working on how to even use stack overflow... so my line breaks are non existent – amt Feb 15 '18 at 14:11
  • Could you edit your question, then paste your code in there, mark the whole code and then click the button with {} to format the code correctly? Maybe It's possible to see what the formula is supposed to look like – FlyingTeller Feb 15 '18 at 14:14
  • I edited it. Thanks for the help! – amt Feb 15 '18 at 14:17
  • Pretty sure now that it is the typo I have pointed out. Try that: `y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t)` – FlyingTeller Feb 15 '18 at 14:18
  • That worked along with adding plt.show(). Thank you! – amt Feb 15 '18 at 14:21
  • Glad you got it working – FlyingTeller Feb 15 '18 at 14:26

1 Answers1

2

To summarize the answer from the comments:

x = 16 * np.sin(t)**3
y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cost(3*t)-np.cos(4*t)

contains a small typo in the formula for y and should be

y = 13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t)

which, together with the x coordinates is the parametrization of a curve that resembles a heart shape

FlyingTeller
  • 17,638
  • 3
  • 38
  • 53