Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:33:01+00:00 2026-06-05T00:33:01+00:00

I want to vectorize the following function. The arguments are numpy arrays. def euclidean_distance(dl,

  • 0

I want to vectorize the following function. The arguments are numpy arrays.

def euclidean_distance(dl, dr):
    return math.sqrt(((dl - dr) ** 2).sum())

I do the following

v_u = numpy.vectorize(euclidean_distance)

and I am doing the following call

v_u(numpy.array([[10, 20, 30], [4, 5, 6]]), numpy.array([1, 2, 3]))

What I want is that I get back an array which contains the euclidean distance of [1, 2, 3] with [10, 20, 30], [4, 5, 6].

I think I am missing something obvious.

EDIT:
The following is the error I get

AttributeError: 'int' object has no attribute 'sum'

which is obvious that dl and dr are passed as single elements but not as arrays…
So I was wondering if somebody could correct it so that it operated on arrays.

Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:33:03+00:00Added an answer on June 5, 2026 at 12:33 am

    Why do you need vectorize for that?

    You can use shape broadcasting and do something like:

    dist = numpy.sqrt(numpy.sum((d1-dr)**2, axis = 1))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to vectorize the following MATLAB code. I think it must be simple
Want to use signal when follow() function called in UserProfile. I've written signal which
Want the function to sort the table by HP but if duplicate HPs then
I have a Python program that processes fairly large NumPy arrays (in the hundreds
I want to create an array in numpy that contains the values of a
Imagine you have an RGB image and want to process every pixel: import numpy
I want to access the vector in the manipulatevector function below the same way
I want to vectorize this double for loop because it is a bottleneck in
I want to vectorize code for Core2. I think, I can use intrinsic functions
Is it possible to vectorize the loop below? % String to parse (we want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.