module 'numpy' has no attribute 'linarg'?

Asked 1 years ago, Updated 1 years ago, 70 views

After running the following program,

#coding:utf-8


import numpy as np

defcos_sim(v1,v2):
    return np.dot(v1, v2)/(np.linarg.norm(v1)*np.linarg.norm(v2)))


x = np.array ([1,1,1,1,1,1])
y = np.array ([1,0,1,0,1])
z = np.array ([0,1,0,0,0])

print(cos_sim(x,y))
print(cos_sim(y,z))
print(cos_sim(z,x))

The following error occurred:

/.PyCharmCE 2018.2/config/scratches/scratch.py
Traceback (most recent call last):
  File "C:/Users/komaaaaari/.PyCharmCE 2018.2/config/scratches/scratch.py", line 14, in <module>
    print(cos_sim(x,y))
  File "C:/Users/komaaaaari/.PyCharmCE 2018.2/config/scratches/scratch.py", line 7, incos_sim
    return np.dot(v1, v2)/(np.linarg.norm(v1)*np.linarg.norm(v2)))
AttributeError: module 'numpy' has no attribute 'linarg'

Process finished with exit code 1

I saw a similar example and reinstalled numpy, but I couldn't solve it, so I'd like to ask for your help. I'm not familiar with python, so it's refreshing.Thank you for your cooperation.

python numpy

2022-09-30 21:35

1 Answers

The linarg specified as the name is incorrect for linalg (linear algebra = LINear ALGebra).
linalg has various operations defined in linear algebra.

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

There is an error message.
This means that the numpy module does not have the attribute linarg.
You can read that the linarg specification is suspicious.

Now that you know this, here are some tips for debugging afterwards:

and so on.


2022-09-30 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.