Skip to content

cosine.cosine_distance: ComplexWarning: Casting complex values to real discards the imaginary part #22

@lemarcantoine

Description

@lemarcantoine

Hello, when running:

import numpy as np
import ABXpy.distances.metrics.cosine as cosine

a = np.array([[1.17004299, 0.85545695, 1.00981605, 1.16844952, 0.63780457, 0.86987048]])
cosine.cosine_distance(a, a)

I get the following warning:

/home/username/anaconda3/lib/python3.7/site-packages/ABXpy/distances/metrics/cosine.py:25: ComplexWarning: Casting complex values to real discards the imaginary part
  d = np.array([[np.float64(np.lib.scimath.arccos(d[0, 0]) / np.pi)]])

I believe its because the inner intermediate d var is slightly higher than 1 because of a float rounding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions