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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:08:50+00:00 2026-05-24T10:08:50+00:00

I have a large array with 1024 entries that have 7 bit values in

  • 0

I have a large array with 1024 entries that have 7 bit values in range(14, 86)

This means there are multiple range of indices that have the same value.

For example,

consider the index range 741 to 795. It maps to 14
consider the index range 721 to 740. It maps to 15
consider the index range 796 to 815. It maps to 15

I want to feed this map to a python program that would spew out the following:

if((index >= 741) and (index <= 795)) return 14;
if((index >= 721) and (index <= 740)) return 15;
if((index >= 796) and (index <= 815)) return 15;

Some code to groupby mapped value is ready but I am having difficulty coding up an expression using pairwise.

Anyone has done something similar before?

I have uploaded the dataset in two forms:

Usual, ordered by index.

Grouped by mapped value.

  • 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-05-24T10:08:50+00:00Added an answer on May 24, 2026 at 10:08 am

    After closing, I belatedly found this solution “What’s the most Pythonic way to identify consecutive duplicates in a list?”.


    NB: with a periodic fn like sine, you can get by by only storing a quarter (i.e. 256 values) or half of the table, then perform a little (fixed-point) arithmetic on the index at lookup time. As I commented, if you further don’t store the offset of +50, you need one bit less, at the cost of one integer addition after lookup time. Hence, 79% compression easily achievable. RLE will give you more. Even if the fn has noise, you can still get decent compression with this general approach.

    As agf pointed out, your f(n) = 50 + 36*sin(72*pi*n/1024) = 50 + g(n), say.

    So tabulate the 256 values of g(n) = 36*sin(72*pi*n/1024), only for the range n=0..255

    Then f(n) is easily computed by:

    if 0 <= n < 256, f(n) = 50 + g(n)
    if 256 <= n < 512, f(n) = 50 + g(511-n)
    if 512 <= n < 768, f(n) = 50 - g(n-512)
    if 768 <= n < 1024, f(n) = 50 - g(1023-n)
    

    Anyway here’s a general table compressor solution which will generate (istart,iend,value) triples.

    I knocked my head off how to do this more Pythonically using list comprehensions and itertools.takewhile() ; needs polishing.

    #import itertools
    
    table_="""
        0       50
        1       50
        ...
        1021    49
        1022    50
        1023    50""".split()
    
    # Convert values to int. Throw away the indices - will recover them with enumerate()
    table = [int(x) for x in table_[1::2]]
    
    compressed_table = []
    istart = 0
    for i,v in enumerate(table):
        if v != table[i-1]:
            iend = i-1
            compressed_table.append((istart,iend,table[i-1]))
            istart = i
        else:
            continue # skip identical values
    # Slightly ugly: append the last value, when the iterator was exhausted
    compressed_table.append((istart,i,table[i]))
    

    (NB I started the table-compressor approach before agf changed his approach… was trying to get an itertools or list-comprehension solution)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large array in C (not C++ if that makes a difference).
I have a large 2d array that I serialize and base64_encode and throw into
So I have a large 2d array that i serialize, but when I attempt
Background: I have a large 2D array of integers that I need to load
I have a large array of vertices, some of them are edges, some are
Imagine you have a large array of floating point numbers, of all kinds of
I have a large int[] array and a much smaller int[] array. I want
I have large batches of XHTML files that are manually updated. During the review
I'm developing a website in PHP and I have large JS files that I
I have a large array (say 512K elements), GPU resident, where only a small

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.