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

  • Home
  • SEARCH
  • 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 4037216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:19:11+00:00 2026-05-20T12:19:11+00:00

I have a black and white image which every pixel values are loaded as

  • 0

I have a black and white image which every pixel values are loaded as a nested list with numpy (2948×1536). What i need to do is to grab the pixels from that list in a checkerboard pattern. So I need to extract pixels like this :

0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
….

How would this be done ? Is this a good idea to use a nested list for such a job ? If not, what would you suggest ?

Image processing is quite new to me.

Any help would be greatly appreciated,

  • 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-20T12:19:12+00:00Added an answer on May 20, 2026 at 12:19 pm

    Let’s use smaller dimensions so the result is easier to see:

    import numpy as np
    # w=2948
    # h=1536
    w=6
    h=4
    arr=np.arange(w*h).reshape(w,h)
    print(arr)
    print(arr.shape)
    # [[ 0  1  2  3]
    #  [ 4  5  6  7]
    #  [ 8  9 10 11]
    #  [12 13 14 15]
    #  [16 17 18 19]
    #  [20 21 22 23]]
    # (6, 4)
    

    We can construct a boolean array in a checkerboard pattern:

    coords=np.ogrid[0:w,0:h]
    idx=(coords[0]+coords[1])%2 == 1
    print(idx)
    print(idx.shape)
    # [[False  True False  True]
    #  [ True False  True False]
    #  [False  True False  True]
    #  [ True False  True False]
    #  [False  True False  True]
    #  [ True False  True False]]
    # (6, 4)
    

    Using this boolean array for indexing, we can extract the values we desire:

    checkerboard=arr[idx].reshape(w,h//2)
    print(checkerboard)
    print(checkerboard.shape)
    # [[ 1  3]
    #  [ 4  6]
    #  [ 9 11]
    #  [12 14]
    #  [17 19]
    #  [20 22]]
    # (6, 2)
    

    PS. Inspiration for this answer came from Ned Batchelder’s answer here.

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

Sidebar

Related Questions

I have an image which is pretty much b&w and it has a black
What I am supposed to do. I have an black and white image (100x100px):
i have a input tag which is non editable, but some times i need
I need to implement a class which will be used for same image operations.
I have a gif image which is way too big for my needs (even
I have a function called bodyStyle() which accepts 5 values: bodyStyle(textCol, backCol, heading1Col, headingsCol,
I need to create module in Magento which will have few database tables. One
I have an icon.png which has white background with a blue faced cartoon. Something
I have the following HTML (note the CSS making the background black and text
If I have a HUD NSPanel that is black/transparent and I add some controls

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.