logo
down
shadow

Scipy Negative Distance? What?


Scipy Negative Distance? What?

By : mattycfp
Date : January 02 2021, 06:48 AM
it should still fix some issue This is because of floating-point inaccuracy, so some distances between your vectors, instead of being 0, are for example -0.000000000000000002. Use scipy.clip() function to correct the problem. If your distance matrix is dmatr, use numpy.clip(dmatr,0,1,dmatr) and you should be ok.
code :


Share : facebook icon twitter icon
Negative results occurs when calculate cross-track distance(distance between line segment and point on sphere)

Negative results occurs when calculate cross-track distance(distance between line segment and point on sphere)


By : Jordav
Date : March 29 2020, 07:55 AM
Hope that helps It can happen if the coordinates of (x,y) are in fact values under (x",y"). That doesn't mean that the value is negative, but that the substraction is always made in the same order:
code :
(x-x"), (y-y"). 
finding the distance between a set of points using scipy.spatial.distance.cdist(X, Y) in python

finding the distance between a set of points using scipy.spatial.distance.cdist(X, Y) in python


By : Devanopy
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Two solutions:
calculate the complete matrix directly, and the access the q-th column for the values between A and B[q].
code :
d = scipy.spatial.distance.cdist(A,B)

for q in range(len(B)):
    y = d[:,q]
    print y
for q in range(len(B)):
    y = scipy.spatial.distance.cdist(A,[B[q]])
    print y
python how to get proper distance value out of scipy condensed distance matrix

python how to get proper distance value out of scipy condensed distance matrix


By : Carlo Monti
Date : March 29 2020, 07:55 AM
should help you out This vector is in condensed form. It enumerates all pairs of indices in a natural order (in your example 0,1 0,2 0,3 0,4 1,2 1,3 1,4 2,3 2,4 ) and yields the distance between the elements at these array entries.
There is also the squareform function, which transforms the condensed form into a square matrix form (and vice versa). The square matrix form is exactly what you expect, i.e. at entry ij (row i, column j), it stores the distance between the i-th and j-th entry. For example, if you add print squareform(d) at the end of you code, the output will be:
code :
array([[ 0.,  3.,  1.,  4.],
       [ 3.,  0.,  4.,  1.],
       [ 1.,  4.,  0.,  5.],
       [ 4.,  1.,  5.,  0.]])
Distance transform with Manhattan distance - Python / NumPy / SciPy

Distance transform with Manhattan distance - Python / NumPy / SciPy


By : Thomas
Date : March 29 2020, 07:55 AM
help you fix your problem Here's one with Scipy cdist -
code :
from scipy.spatial.distance import cdist

def bwdist_manhattan(a, seedval=1):
    seed_mask = a==seedval
    z = np.argwhere(seed_mask)
    nz = np.argwhere(~seed_mask)

    out = np.zeros(a.shape, dtype=int)
    out[tuple(nz.T)] = cdist(z, nz, 'cityblock').min(0).astype(int)
    return out
In [60]: a # input binary image with 1s at "seed" positions
Out[60]: 
array([[1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0]])

In [61]: bwdist_manhattan(a)
Out[61]: 
array([[0, 1, 2, 3, 4, 4, 3, 4],
       [1, 2, 3, 4, 4, 3, 2, 3],
       [2, 3, 4, 4, 3, 2, 1, 2],
       [3, 4, 4, 3, 2, 1, 0, 1],
       [4, 5, 5, 4, 3, 2, 1, 2]])
Scipy Sparse - distance matrix (Scikit or Scipy)

Scipy Sparse - distance matrix (Scikit or Scipy)


By : Waleed Ibrahim
Date : March 29 2020, 07:55 AM
it should still fix some issue First, you can't use KDTree and pdist with sparse matrix, you have to convert it to dense (your choice whether it's your option):
Related Posts Related Posts :
  • google app engine error ,and i can't open it now.(python)
  • IIS Not Linking to Django with PyISAPIe
  • Create two separate windows in terminal
  • Killing a subprocess including its children from python
  • google search rankings and trends api
  • Easiest way to automatically download required modules in Python?
  • How to read a string one letter at a time in python
  • Python pixel manipulation library
  • python cx_Freeze egg problem
  • How can I select all rows with sqlalchemy?
  • Converting IPv4 or IPv6 address to a long for comparisons
  • Converting BMP to Grey Scale in Image Module Python
  • Python: Memory usage and optimization when modifying lists
  • Mod_wsgi versus fapws3 - Django
  • In Django, how to create tables from an SQL file when syncdb is run
  • What's the pythonic way to use getters and setters?
  • python regular expression for domain names
  • Pickling a class definition
  • How to catch login failures with PySVN?
  • Python: how to enclose strings in a list with < and >
  • Python: finding lowest integer
  • efficiently finding the interval with non-zeros in scipy/numpy in Python?
  • How to convert Selenese (html) to Python programmatically?
  • fade out in Image module Python
  • local variable 'sresult' referenced before assignment
  • how to transfer a python object between two requests?
  • Getting weird python error when I run a simple django script in Eclipse, not happening in console
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk