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 8250927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:04:11+00:00 2026-06-08T00:04:11+00:00

I am trying to match a small array with size of ~20 in an

  • 0

I am trying to match a small array with size of ~20 in an larger array with size of ~200000. Both arrays contains double values. Match in this case means the smallest error, because there won’t be an exact match.

Next thing is, that I have to change the values of the small array, because it should also match if it’s different but has same gaps between the values, which means:

array 1: [1.3, 1.4, 1.3, 1.5, 1.7]
array 2: [..., 2.3, 2.4, 2.4, 2.5, 2.7, ...]

I have to bring the last element of each comparison to the same number. There the above example would be an extremely good match because first i would +1.0 the whole array #1.

[edit]
To clarify the above statement: Before calculating the error the example array should look like this:

array 1: [2.3, 2.4, 2.3, 2.5, 2.7] 
// (+1 of each element so the last element of the small array, 
// and the last element of the part of the large array I am 
// comparing to, has the same values: in this case: 2.7)
array 2: [..., 2.3, 2.4, 2.4, 2.5, 2.7, ...]

[/edit]

I know it is possible to simply iterate through the big array, but it is too slow. And of course instead of calculating the error by iterating through the array i can use vector operations like norm(v1 – v2).

So i have heard, that python is quite good for math operations, but i couldn’t find anything how to compare 2 arrays (just one number in an array).

Finally, the question is: Any ideas, how i can solve the problem in a really fast way. Which language is good to solve these kinds of problem (octave isn’t because it’s just fast at vector calculation, but slow with iterations) – probably there are some good libraries at python?

Let me know if I have to explain it more detailed.

  • 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-08T00:04:13+00:00Added an answer on June 8, 2026 at 12:04 am

    I admit that I’m a little fuzzy on how your defining best match, but this example can be adjusted pretty easily. The magic is in the closeness function which receives a slice of data which is the same length as target and returns a number. The lower the number, the better the match.

    import random
    
    target = [random.random() * 10 for i in range(20)]
    data   = [random.random() * 10 for i in range(200000)]
    
    def closeness(a_range):
        diffs = list(map(lambda e: e[0]-e[1], zip(a_range, target)))
        avg_diffs = float(sum(diffs)) / len(diffs)
        adjusted_target = [i + avg_diffs for i in target]
        return sum(adjusted_target)
    
    ranges = [data[i:i+len(target)] for i in range(len(data)-len(target))]
    best_match = min(ranges, key=closeness) 
    
    print(best_match)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to match the '12345' from a url in this form: http://domain.com/folder/title_of_this_12345 So
I am trying to match for country or Country using lower-case function in XPath.
Trying to write this small program to help me in my Stats class, everything
I'm trying to select a small set of records that match a patten I
I am trying to match (using regex in python): http://images.mymaterials.com/images/steel-images/small/steel/steel800/steel800-2.jpg in the following string:
I am trying to add Match Whole Word search to my small application. I
I'm trying to implement this in a small ruby script, and tested it on
I'm trying to match out of this text: <a href=http://english317.ning.com/profiles/blogs/bad-business-writing-487>Continue</a> </div> <p class=small> Added
Im trying to match forum_id with several different forum_id's, something like forum_id = 5,7,12,43,63,78
I'm trying to match a string against a pattern, but there's one thing I

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.