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

  • Home
  • SEARCH
  • 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 8945583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:16:54+00:00 2026-06-15T12:16:54+00:00

I’ve got a large input matrix (4000×10000). I use dist() to calculate the Euclidean

  • 0

I’ve got a large input matrix (4000×10000). I use dist() to calculate the Euclidean distance matrix for it (it takes about 5 hours).
I need to calculate the distance matrix for the “same” matrix with an additional row (for a 4001×10000 matrix). What is the fastest way to determine the distance matrix without recalculating the whole matrix?

  • 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-15T12:16:54+00:00Added an answer on June 15, 2026 at 12:16 pm

    I’ll assume your extra row means an extra point. If it means an extra variable/dimension, it will call for a different answer.

    First of all, for euclidean distance of matrices, I’d recommend the rdist function from the fields package. It is written in Fortran and is a lot faster than the dist function. It returns a matrix instead of a dist object, but you can always go from one to the other using as.matrix and as.dist.

    Here is (smaller than yours) sample data

    num.points <- 400
    num.vars   <- 1000
    original.points <- matrix(runif(num.points * num.vars),
                              nrow = num.points, ncol = num.vars)
    

    and the distance matrix you already computed:

    d0 <- rdist(original.points)
    

    For the extra point(s), you only need to compute the distances among the extra points and the distances between the extra points and the original points. I will use two extra points to show that the solution is general to any number of extra points:

    extra.points <- matrix(runif(2 * num.vars), nrow = 2)
    inner.dist   <- rdist(extra.points)
    outer.dist   <- rdist(extra.points, original.points)
    

    so you can bind them to your bigger distance matrix:

    d1 <- rbind(cbind(d0, t(outer.dist)),
                cbind(outer.dist, inner.dist))
    

    Let’s check that it matches what a full, long rerun would have produced:

    d2 <- rdist(rbind(original.points, extra.points))
    
    identical(d1, d2)
    # [1] TRUE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My input file is a large txt file with concatenated texts I got from
I got a large PHP website which I'm now about to take care of.
I've got a very large table (~100Million Records) in MySQL that contains information about
I've got a large HTML data entry table, implemented as a large matrix of
I've got a large form where the user is allowed to input many different
I've got a large scale single page app that I'm migrating to Dojo 1.7/AMD
I've got a large table that lists out approximately 50 users and some simple
I've got a large amound of data I'm sending down to the client using
I've got a large table in a SQL Server 2005 database and I'd like
We've got this large application written in Delphi 5, and development is ongoing to

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.