473,785 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding euclidean distance,better code?

hello
while trying to write a function that processes some numpy arrays and
calculate euclidean distance ,i ended up with this code
(though i used numpy ,i believe my problem has more to do with python
coding style..so am posting it here)

....
# i am using these numpy.ndarrays to do the calculation
facespace # of shape(totalimgs ,imgpixels)
weights # of shape(totalimgs ,selectedfacesp aces)
input_wk # of shape(selectedf acespaces,)
distance # of shape(selectedf acespaces,) initally all 0.0 's
mindistance #of shape(selectedf acespaces,) initally all
0.0 's
....
....
#here is the calculations part

for image in range(numimgs):
distance = abs(input_wk - weights[image, :])
if image==0:
#copy from distance to mindistance
mindistance=dis tance.copy()
if sum(mindistance ) sum(distance):
imgindex=image
mindistance=dis tance.copy()
if max(mindistance ) 0.0:
#normalise mindistance
mindistance=min distance/(max(mindistanc e)+1)
dist=sum(mindis tance)

this gets me the euclidean distance value.I want to know if the way i
coded it can be improved,made more compact....if someone can give
suggestions it will be a great help .
thanks
D
Mar 17 '08
11 6379
Steven D'Aprano schreef:
On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
>Gabriel Genellina wrote:
>>That's what I said in another paragraph. "sum of coordinates" is using
a different distance definition; it's the way you measure distance in a
city with square blocks. I don't know if the distance itself has a
name, but
I think it is called Manhattan distance in reference of the walking
distance from one point to another in this city.

You know, there are other cities than Manhattan. Some of them even have
streets and blocks.
I'm not sure what your point is. The name of the distance happens to be
Manhattan distance (or taxicab distance, rectilinear distance, L1
distance, city block distance; see
http://en.wikipedia.org/wiki/Manhattan_distance) so Robert has a valid
point.
--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
-- Isaac Asimov

Roel Schroeven
Mar 29 '08 #11
On Sat, 29 Mar 2008 13:06:27 +0100, Roel Schroeven wrote:
In any case, I replied because your reaction didn't feel all that gentle
to me; to be honest, it felt rather rude.
Are you new to Usenet? :-)

No offense taken; I hope Robert didn't take offense either, but took the
little dig in the spirit it was intended.

--
Steven
Mar 29 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
3904
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes are pre-calculated and passed to the query. SELECT * FROM Locations
6
4054
by: Christoph Pingel | last post by:
Hi all, an interesting problem for regex nerds. I've got a thesaurus of some hundred words and a moderately large dataset of about 1 million words in some thousand small texts. Words from the thesaurus appear at many places in my texts, but they are often misspelled, just slightly different from the thesaurus. Now I'm looking for the best strategy to match the appearence of my thesaurus items in the texts. Do I have to build patterns...
6
3779
by: Joe | last post by:
I have a: vector<string> which contains a few dozen elements. I want to find the index of the element containing a certain string. for example: vector<string> strings; strings.push_back("abc"); strings.push_back("xyz"); strings.push_back("lmnop");
20
17050
by: Webdad | last post by:
Hi! I running my first year as industrial engineer (informatics) We have an assignment to do : .... create a playfield (matrix). Some places in that field are blocked, so you can't pass them. The others are free to go over ... (I already found that part) -> http://users.pandora.be/hebbrecht/jochen/c++/test.cpp
2
3309
by: B Moor | last post by:
I have a database with 100,000's records, each with a unique reference, eg A123BNK456 I would like to generate a search facility whereby we can choose an exact match or partial match, where the partial match could be any of the following:- Partial match 1: 1 character maybe wrong Partial match 2: 2 characters maybe wrong Partial match 3: 3 characters maybe wrong
14
11335
by: Tiza Naziri | last post by:
Hi, Anybody have an idea on how to start writing a C code for generating the inverse of finite field GF(2^8) using extended Euclidean algorithm? What I mean is how to represent a polynomial, e.g. f(x)=x^8+x^4+x^3+x+1 in C? How to represent the multiplication & division process of polynomial? Regards.
9
2325
by: nottheartistinquestion | last post by:
As an intellectual exercise, I've implemented an STL-esque List<and List<>::Iterator. Now, I would like a signed distance between two iterators which corresponds to their relative position in the list. For instance, if I did something like distance(list.end(), list.begin()), I would get -list.size(). The STL's iterator distance function amounts to something like this: distance_type distance(Iterator first, Iterator last) {...
5
2561
by: pepito72 | last post by:
Hi A problem with trying to find the nearest colour. I have an image which I use GetPixel to return the colour of various points. However .... not all colours returned will be a System/Known/Pre- defined colour. So they wont have corresponding names - this is a problem because my app needs to return the colour name of each pixel. So I have looked at GetNearestColor but this just seems to return the original color I passed it in the...
1
14207
by: Glenton | last post by:
Hi All Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm: #!/usr/bin/env python #This is meant to solve a maze with Dijkstra's algorithm from numpy import inf from copy import copy
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.