#Problem with embedding format for distance calculation

1 messages · Page 1 of 1 (latest)

last nimbus
#

I am using this code to calculate distance:

if distance_metric == 'cosine':
             distances = cdist(q_embeddings, embeddings, metric='cosine')[0]
         elif distance_metric == 'euclidean':
             distances = cdist(q_embeddings, embeddings, metric='euclidean')[0]
         else:
             raise ValueError()

but I am getting this error:

setting an array element with a sequence.

Which of these models is suitable for the code to work?

q_embedding: [[-0.07111082]
  [0.00781175]
  [0.02218405]
  ...
  [0.00392763]
  [-0.04517321]
  [0.05226689]]

embeddings: [[array([ 0.02584562, 0.02505668, 0.02483578, ..., -0.00870988,
           0.00877299, 0.03758502]) ]
  [array([ 0.01276193, -0.00347997, 0.05607365, ..., 0.00732333,
           0.00179388, 0.00466562]) ]

If neither, which one is it?