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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:22:14+00:00 2026-06-17T11:22:14+00:00

Is it possible (in terms of performance) to have a single multi-dimensional array that

  • 0

Is it possible (in terms of performance) to have a single multi-dimensional array that contains one 8-bit integer per pixel, for each pixel in the game window? I need to update the game window in a timely manner based on this array.

I’m aiming for something like the following:

import numpy
window_array = numpy.zeros((600, 600), dtype=numpy.int8)

#draw the screen
for (y, x), value in numpy.ndenumerate(window_array):
    if value == 1:
        rgb = (0, 0, 0)
    elif value == 2:
        rgb = (50, 50, 50)
    blit_pixel(x, y, rgb)

I’d like to be going 30-60 FPS, but so far my tests have yielded results that were much too slow to run at even a bad framerate. Is it possible to do, and if so, how?

  • 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-17T11:22:16+00:00Added an answer on June 17, 2026 at 11:22 am

    I have never used pygame, so take my anwser with a grain of salt…

    That said, it seems very unlikely that you are going to get any decent frame rate if you are iterating over 360,000 pixels with a python loop and doing a python function call at each one.

    I learned from this other question (read the comment thread) that the pygame.surfarray module will give you a reference to the array holding the actual screen data. pygame.surfarray.pixels3d should return a reference to an array of shape (rows, cols, 3) where the last dimension holds the RGB values on screen. With that reference, you can change the pixels on screen directly, without needing a python loop doing something like:

    import numpy
    surf_array = pygame.surfarray.pixels3d(surface)
    window_array = numpy.zeros(surf_array.shape[:2], dtype=numpy.int8)
    ...
    surf_array[numpy.nonzero(window_array == 1)] = np.array([0, 0, 0])
    surf_array[numpy.nonzero(window_array == 2)] = np.array([50, 50, 50])
    

    Not sure if a call to pygame.display.update is needed to actually show your changes, but this approach will sustain a much, much higher frame rate than what you had in mind.

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

Sidebar

Related Questions

Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
I have a file with int values in each line (although it's possible that
A quick ASP.Net performance question... I have an ASP.Net 3.5 SP1 Application that I
Is it possible to extract the list of all the terms in a Lucene
Is it possible to handle this event in some way? What happens in terms
Question: In terms of program stability and ensuring that the system will actually operate,
I have a DAL that is replicated across multiple apps (I know its a
If i takes larger datatype where i know i should have taken datatype that
I have code such that: while(isResponseArrived) Thread.yield(); But what I'd really like to do
I have a piece of mature geospatial software that has recently had areas rewritten

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.