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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:44:02+00:00 2026-06-05T21:44:02+00:00

I often work with multidimensional arrays whose array indices are generated from a complicated

  • 0

I often work with multidimensional arrays whose array indices are generated from a complicated user-specified set.

I’m looking for a library with classes for representing complicated sets with an arbitrary number of indices, and arbitrarily complicated predicates. Given a set description, the desired output would be a generator. This generator would in turn produce either dicts or tuples which correspond to the multidimensional array indices.

Does such a library exist?


Example

Suppose we had the following user-specified set (in set-builder notation), which represents the indices of some array variable x[i][j]:

{i in 1..100, j in 1..50: i >= 20, j >= 21, 2*(i + j) <= 100}

I’d like to put this into some sort of a lazy class (a generator expression perhaps) that will allow me to lazily evaluate the elements of the set to generate the indices for my array. Suppose this class were called lazyset; this would be the desired behavior:

>>> S = lazyset("{i in 1..100, j in 1..50: i >= 20, j >= 21, 2*(i+j) <= 100}")
>>> S
<generator object <genexpr> at 0x1f3e7d0>
>>> next(S)
{'i': 20, 'j': 21}
>>> next(S)
{'i': 20, 'j': 22}

I’m thinking I could roll my own using generator expressions, but this almost seems like a solved problem. So I thought I’d asked if anyone’s come across an established library that handles this (to some extent, at least). Does such a library exist?

  • 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-05T21:44:03+00:00Added an answer on June 5, 2026 at 9:44 pm

    This looks more like a constraint-solver problem to me:

    import constraint as c
    
    p = c.Problem()
    p.addVariable(0, range(1,101))
    p.addVariable(1, range(1,51))
    p.addConstraint(lambda i: i >= 20, [0])
    p.addConstraint(lambda j: j >= 21, [1])
    p.addConstraint(c.MaxSumConstraint(50))
    
    indices = ((s[0], s[1]) for s in p.getSolutionIter())  # convert to tuple generator
    

    then if you do

    for ij in indices:
        print ij
    

    you get

    (29, 21)
    (28, 22)
    (28, 21)
    (27, 23)
    (27, 22)
    (27, 21)
    
    ...
    
    (20, 25)
    (20, 24)
    (20, 23)
    (20, 22)
    (20, 21)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TFS server and I often work from two places. I'd like
Often functions that work with data.frames have the ability to let the user provide
Where I work, I often see code like that : public void Test(Models.User.UserInfo userInfo,
I often work in Eclipse, but recently switched to TextMate, which is, in my
As a freelancer, I often work at companies who use Subversion repositories. It’d be
At my company, we develop our ASP.NET applications as websites and often just work
I often like to create backups when testing the software I work on, and
I work on applications developed in C#/.NET with Visual Studio. Very often ReSharper, in
I often want to send sample apps to friends & colleages that work with
At the company that I work with, we often have to integrate with client’s

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.