TypeError: unsupported operand type(s) for *: 'CommentedMap' and 'CommentedMap' Hatam bu nasıl çözebilirim ?

0 votes
from ruamel import yaml
from scipy import spatial
import ruamel.yaml

with open('trainer.txt') as fin:
    fin.readline()
    rfr =ruamel.yaml.round_trip_load(fin)
    x= rfr['opencv_lbphfaces']['histograms']
#print(rfr['opencv_lbphfaces']['histograms'])
with open('trainer1.txt') as fin:
    fin.readline()
    rfr1 = ruamel.yaml.round_trip_load(fin)
    y= rfr1['opencv_lbphfaces']['histograms']
#print(rfr1['opencv_lbphfaces']['histograms'])

vector1 = [x]
vector2 = [y]

#print(vector1,vector2)

cosine_similarity = spatial.distance.cosine(vector1, vector2)
print(cosine_similarity)
Sep 29 in Python by anonymous
• 120 points

edited Sep 29 by Gitika 45 views

Merhaba,

özellikle hangi satırda hatayla karşılaştığınızı belirtebilir misiniz? Hata, veri türünün uyumsuzluğundan kaynaklanmaktadır. Python'daki operatörler aynı veri türünün çalışmasını destekler. Bir operatör iki farklı veri türü için kullanıldığında, bu tür bir uyumsuzluk hatası atılacaktır.

Traceback (most recent call last):

  File "C:\Users\asus\Desktop\Poje2\untitled1.py", line 21, in <module>
    cosine_similarity = spatial.distance.cosine(vector1, vector2)

  File "C:\Users\asus\anaconda3\lib\site-packages\scipy\spatial\distance.py", line 766, in cosine
    return correlation(u, v, w=w, centered=False)

  File "C:\Users\asus\anaconda3\lib\site-packages\scipy\spatial\distance.py", line 717, in correlation
    uv = np.average(u * v, weights=w)

ValueError: operands could not be broadcast together with shapes (19,) (20,)

böyle bir hatayla karşılaşıyorum

Hey dostum

iki matrisi çarpmaya çalışıyorsanız (doğrusal cebir anlamında), X.dot (y) istersiniz, ancak y matrisinden X üzerine skaler yayınlamaya çalışıyorsanız, o zaman X * y.T yapmanız gerekir.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

TypeError: unsupported operand type(s) for -: 'str' and 'str'

Hi. This error is caused because you ...READ MORE

answered May 12, 2019 in Python by Anjali
33,684 views
0 votes
0 answers

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Hi guys i have below code . ...READ MORE

Oct 30, 2019 in Python by sumanth
• 190 points
5,976 views
0 votes
1 answer

TypeError: unsupported operand type(s) for -: 'list' and 'int'

Hey, @William For me the code is working ...READ MORE

answered Mar 11 in Python by Roshni
• 4,530 points
705 views
+1 vote
0 answers

TypeError: unsupported operand type(s) for /: 'list' and 'list'

This is my part of code, why ...READ MORE

May 17 in Python by anonymous
• 220 points

edited May 18 by Gitika 350 views
0 votes
1 answer

Test Failed: unsupported operand type(s) for -: 'tuple' and 'list'

Hi, @There, Check what are you passing.. the ...READ MORE

answered Oct 5 in Python by Gitika
• 41,080 points
77 views
+2 votes
0 answers

unsupported operand type error

tech_list=closingdata.pct_change() tech_list READ MORE

Jan 26 in Python by Anupriya
• 140 points
200 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,446 views
0 votes
0 answers