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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:40:46+00:00 2026-06-06T17:40:46+00:00

I am stuck on this one piece of code because I can’t get the

  • 0

I am stuck on this one piece of code because I can’t get the generator to return me a the next value every time its called – it just stays on the first one! Take a look:

from numpy import *

def ArrayCoords(x,y,RowCount=0,ColumnCount=0):   # I am trying to get it to print
    while RowCount<x:                            # a new coordinate of a matrix
        while ColumnCount<y:                     # left to right up to down each
            yield (RowCount,ColumnCount)         # time it's called.
            ColumnCount+=1
        RowCount+=1
        ColumnCount=0

Here is what I get:

>>> next(ArrayCoords(20,20))
... (0, 0)
>>> next(ArrayCoords(20,20))
... (0, 0)

But it’s just stuck on the first one! I expected this:

>>> next(ArrayCoords(20,20))
... (0, 0)
>>> next(ArrayCoords(20,20))
... (0, 1)
>>> next(ArrayCoords(20,20))
... (0, 2)

Could you guys help me out with the code as well as explain why it is so?
Thank you in advance!

  • 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-06T17:40:50+00:00Added an answer on June 6, 2026 at 5:40 pm

    Each time you call ArrayCoords(20,20) it returns a new generator object, different to the generator objects returned every other time you call ArrayCoords(20,20). To get the behaviour you want, you need to save the generator:

    >>> coords = ArrayCoords(20,20)
    >>> next(coords)
    (0, 0)
    >>> next(coords)
    (0, 1)
    >>> next(coords)
    (0, 2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck and can't figure this out. I have this piece of code which
I've trawled for hours over this piece of jQuery and I still can't get
I am designing a cookbook website and I am stuck on this one problem.
I'm stuck for ideas on this one. I'm working on a CMS that uses
This is probably a simple one to answer, but I'm stuck, so here goes.
I'm stuck with this one! When I alert the object that I stringify the
Hey, I've got this nice little piece of code, much like all the other
I'm stuck on stoopid today as I can't convert a simple piece of ObjC
We had a piece of code in C in one class where we needed
I'm having deadlock problems with this piece of code: def _entropy_split_parallel(data_train, answers_train, weights): CPUS

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.