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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:21:51+00:00 2026-06-02T10:21:51+00:00

Suppose I have a database table with 3 fields: string title, int A, int

  • 0

Suppose I have a database table with 3 fields: string title, int A, int B.
A range of both A and B is 1 to 500.
I want to represent part of the values as a matrix 5×5.
So that (1, 1) will be string which has lowest both A and B;
(5, 5) will have highest both A and B;
(1, 5) will have lowest A and highest B. And so on.
Which algorithm should I use?

  • 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-02T10:21:52+00:00Added an answer on June 2, 2026 at 10:21 am

    I have set up a simulation here and comments will describe the steps.

    First I generate some data: a series of tuples each containing a string and two random numbers representing score A and B.

    Next I divide the ranges of A and B into five equally spaced bins, each representing the minimum and maximum for a cell.

    Then I serially query the data set to extract the strings in each cell.

    There are a hundred ways of optimizing this, based on the actual data structure and storage you are using.

    from random import random
    
    # Generate data and keep record of scores
    data = []
    a_list = []
    b_list = []
    for i in range(50):
        a = int(random()*500)+1
        b = int(random()*500)+1
        rec = { 's' : 's%s' % i,
                'a' : a,
                'b' : b
                 }
        a_list.append(a)
        b_list.append(b)
        data.append(rec)
    
    # divide A and B ranges into five bins
    
    def make_bins(f_list):
        f_min = min(f_list)
        f_max = max(f_list)
        f_step_size = (f_max - f_min) / 5.0
        f_steps = [ (f_min + i * f_step_size,
                     f_min + (i+1) * f_step_size)
                    for i in range(5) ]
        # adjust top bin to be just larger than maximum
        top = f_steps[4]
        f_steps[4] = ( top[0], f_max+1 )
        return f_steps
    
    a_steps = make_bins(a_list)
    b_steps = make_bins(b_list)
    
    # collect the strings that fit into any of the bins
    # thus all the strings in cell[4,3] of your matrix
    # would fit these conditions:
    # string would have a Score A that is
    # greater than or equal to the first element in a_steps[3]
    # AND less than the second element in a_steps[3]
    # AND it would have a Score B that is
    # greater than or equal to the first element in b_steps[2]
    # AND less than the second element in a_steps[2]
    # NOTE: there is a need to adjust the pointers due to
    #       the way you have numbered the cells of your matrix
    
    def query_matrix(ptr_a, ptr_b):
        ptr_a -= 1
        from_a = a_steps[ptr_a][0]
        to_a = a_steps[ptr_a][1]
    
        ptr_b -= 1
        from_b = b_steps[ptr_b][0]
        to_b = b_steps[ptr_b][1]
    
        results = []
        for rec in data:
            s = rec['s']
            a = rec['a']
            b = rec['b']
            if (a >= from_a and
                a < to_a and
                b >= from_b and
                b < to_b):
                results.append(s)
        return results
    
    # Print out the results for a visual check
    total = 0
    for i in range(5):
        for j in range(5):
            print '=' * 80
            print 'Cell: ', i+1, j+1, ' contains: ',
            hits = query_matrix(i+1,j+1)
            total += len(hits)
            print hits
    print '=' * 80
    print 'Total number of strings found: ', total
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a database table with two fields, foo and bar. Neither of
I have 2 fields in a database table: up and down and they both
Suppose that i have a table 't' with fields 'id' int 11, 'name' varchar
Suppose I have a database table that has a timedate column of the last
Suppose I have a database table with columns a, b, and c. I plan
Suppose I have an array that mimics a database table. Each array element represents
Suppose I have an Orders table in my database and a corresponding model class
Suppose I have an Oracle 11.2 database containing the following table: TABLE: SURVEY PARAMETER
Suppose I have two queries on a database table. The queries are defined in
Suppose that I have a table like: class Ticker(Entity): ticker = Field(String(7)) tsdata =

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.