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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:01:53+00:00 2026-05-26T23:01:53+00:00

So I have a string of RGBA image data, each pixel is a byte

  • 0

So I have a string of RGBA image data, each pixel is a byte long. I know the image’s x and y resolution too. Now I want to edit the string in a way which would cause the image to be flipped or reversed vertically, which means have the first “row” of pixels become the last row and the opposite, and like this for all other “rows”. Is there a fast way to do it?

  • 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-26T23:01:54+00:00Added an answer on May 26, 2026 at 11:01 pm

    To do what you want to the letter this is one way to proceed:

    >>> img = 'ABCDEFGHIJKL'
    >>> x, y = 4, 3
    >>> def chunks(l, n):
    ...     for i in xrange(0, len(l), n):
    ...         yield l[i:i+n]
    ... 
    >>> [row for row in chunks(img, x)]
    ['ABCD', 'EFGH', 'IJKL']
    >>> ''.join(reversed([row for row in chunks(img, x)]))
    'IJKLEFGHABCD'
    

    HOWEVER, unless you have very small images, you would be better off passing through numpy, as this is at the very minimum an order of magnitude faster than Cpython datatypes. You should look at at the flipup function. Example:

    >>> A
    array([[ 1.,  0.,  0.],
           [ 0.,  2.,  0.],
           [ 0.,  0.,  3.]])
    >>> np.flipud(A)
    array([[ 0.,  0.,  3.],
           [ 0.,  2.,  0.],
           [ 1.,  0.,  0.]])
    

    EDIT: thought to add a complete example in case you have never worked with NumPy before. Of course the conversion is worth only for images that are not 2×2, as instantiating the array has an overhead….

    >>> import numpy as np
    >>> img = [0x00, 0x01, 0x02, 0x03]
    >>> img
    [0, 1, 2, 3]
    >>> x = y = 2
    >>> aimg = np.array(img).reshape(x, y)
    >>> aimg
    array([[0, 1],
           [2, 3]])
    >>> np.flipud(aimg)
    array([[2, 3],
           [0, 1]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have String variable called jsonString : {"phonetype":"N95","cat":"WP"} Now I want to convert it
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
I have string that I want to chop to array of substrings of given
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have string of 9 letters. string myString = 123987898; I want to retrieve
I have string in the following format. Option1:Option2:Option3:Option4 I want to get these items
I have string object. I need to pass this data to another object of
I have string say ABC,D , now I wish to write a method append(initialStr,
I have String time=02:30 PM means 12 hour format and i want to convert
I have a string (char) and I want to extract numbers out of it.

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.