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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:47:33+00:00 2026-05-26T03:47:33+00:00

please consider this reproducible example: from PIL import Image import numpy as np import

  • 0

please consider this reproducible example:

from PIL import Image
import numpy as np
import scipy.misc as sm
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.cbook as cbook
import urllib

datafile = cbook.get_sample_data('lena.jpg')
lena_pil = Image.open(datafile)
lena_pil_np = np.asarray(lena_pil)

lena_scipy = sm.lena()

lena_tmp = open('lena_tmp.png', 'wb')
lena_tmp.write(urllib.urlopen('http://optipng.sourceforge.net/pngtech/img/lena.png').read())
lena_tmp.close()

lena_mpl = mpimg.imread('lena_tmp.png')

sm.info(lena_pil_np)
sm.info(lena_scipy)
sm.info(lena_mpl)

Output is:

>>> sm.info(lena_pil_np)
class:  ndarray
shape:  (512, 512, 3)
strides:  (1536, 3, 1)
itemsize:  1
aligned:  True
contiguous:  True
fortran:  False
data pointer: 0xb707e01cL
byteorder:  little
byteswap:  False
type: uint8

>>> sm.info(lena_scipy)
class:  ndarray
shape:  (512, 512)
strides:  (2048, 4)
itemsize:  4
aligned:  True
contiguous:  True
fortran:  False
data pointer: 0xb6f7d008L
byteorder:  little
byteswap:  False
type: int32

>>> sm.info(lena_mpl)
class:  ndarray
shape:  (512, 512, 3)
strides:  (6144, 12, 4)
itemsize:  4
aligned:  True
contiguous:  True
fortran:  False
data pointer: 0xb6c7b008L
byteorder:  little
byteswap:  False
type: float32

so all arrays are of different shape and type.

For additional processing I would like this arrays to be represented as in last variable lena.mpl, or just to transform array values to their normalized [0..1] float32 type.

What is the best way to do this?

  • 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-26T03:47:34+00:00Added an answer on May 26, 2026 at 3:47 am
    def normalize(arr):
        arr=arr.astype('float32')
        if arr.max() > 1.0:
            arr/=255.0
        return arr
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
please consider this code: import xml.etree.ElementTree as ET import urllib XML_response = urllib.urlopen('http://www.navlost.eu/aero/metar/?icao=LWSK&dt0=2011-05-03+12%3A00%3A00&c=1&rt=metar').read() tree
Please consider this -probably poorly written- example : class Command; class Command : public
Please consider this example: ( working example ) Style declarations: body {background:#333;font:1em Arial, Helvetica,
Please consider this class: class A { public: //public in this example string a1;
Please consider this example Array ( [1] => search engine optimization [2] => engine
Please consider this simple example. I can't get the text of the state element
Please consider this example. (PHP) class Database{ private $result; private $conn; function query($sql){ $result
Please consider this example, how do we force implicit conversion in function whose second
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()

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.