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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:34:25+00:00 2026-06-16T05:34:25+00:00

I watch out this example: http://scikit-learn.org/stable/auto_examples/plot_digits_classification.html#example-plot-digits-classification-py on handwritten digits in scikit-learn python library. i

  • 0

I watch out this example: http://scikit-learn.org/stable/auto_examples/plot_digits_classification.html#example-plot-digits-classification-py
on handwritten digits in scikit-learn python library.

i would like to prepare a 3d array (N * a* b) where N is my images number (75) and a* b is the matrix of an image (like in the example a 8×8 shape).
My problem is: i have signs in a different shapes for every image: (202, 230), (250, 322).. and give me
this error: ValueError: array dimensions must agree except for d_0 in this code:

#here there is the error:
grigiume = np.dstack(listagrigie)
print(grigiume.shape)
grigiume=np.rollaxis(grigiume,-1)
print(grigiume.shape)

There is a manner to resize all images in a standard size (i.e. 200×200) or a manner to have a 3d array with matrix(a,b) where a != from b and do not give me an error in this code:

data = digits.images.reshape((n_samples, -1))
classifier.fit(data[:n_samples / 2], digits.target[:n_samples / 2])

My code:

import os
import glob
import numpy as np
from numpy import array
listagrigie = []

path = 'resize2/'
for infile in glob.glob( os.path.join(path, '*.jpg') ):
    print("current file is: " + infile )
    colorato = cv2.imread(infile)
    grigiscala = cv2.cvtColor(colorato,cv2.COLOR_BGR2GRAY)
    listagrigie.append(grigiscala)

print(len(listagrigie))

#here there is the error:
grigiume = np.dstack(listagrigie)
print(grigiume.shape)
grigiume=np.rollaxis(grigiume,-1)
print(grigiume.shape)


#last step
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))

# Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)

# We learn the digits on the first half of the digits
classifier.fit(data[:n_samples / 2], digits.target[:n_samples / 2])

# Now predict the value of the digit on the second half:
expected = digits.target[n_samples / 2:]
predicted = classifier.predict(data[n_samples / 2:])

print "Classification report for classifier %s:\n%s\n" % (
classifier, metrics.classification_report(expected, predicted))
print "Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted)

for index, (image, prediction) in enumerate(
    zip(digits.images[n_samples / 2:], predicted)[:4]):
    pl.subplot(2, 4, index + 5)
    pl.axis('off')
    pl.imshow(image, cmap=pl.cm.gray_r, interpolation='nearest')
    pl.title('Prediction: %i' % prediction)

pl.show()
  • 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-16T05:34:26+00:00Added an answer on June 16, 2026 at 5:34 am

    You have to resize all your images to a fixed size. For instance using the Image class of PIL or Pillow:

    from PIL import Image
    image = Image.open("/path/to/input_image.jpeg")
    image.thumbnail((200, 200), Image.ANTIALIAS)
    image.save("/path/to/output_image.jpeg")
    

    Edit: the above won’t work, try instead resize:

    from PIL import Image
    image = Image.open("/path/to/input_image.jpeg")
    image = image.resize((200, 200), Image.ANTIALIAS)
    image.save("/path/to/output_image.jpeg")
    

    Edit 2: there might be a way to preserve the aspect ratio and pad the rest with black pixels but I don’t know how to do in a few PIL calls. You could use PIL.Image.thumbnail and use numpy to do the padding though.

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

Sidebar

Related Questions

Anything one should watch out for when using CF8's CFFEED tag? Oh, here's a
Something like this: sass --watch style.css:(other than root directory) //or sass --watch (other directory
I have a generic function for XMLHttpRequests. as follows: function XMLRequest(address, data){ this.html =
Right now I'm building a website. Here's the link: http://theoew.uuuq.com/home/ This probably won't make
I'm mapping out the name attributes of :input using the example below. I had
Im trying to implement this example, but with $.getScript: and for some reason, it
Russel Peter video: <a rel=nofollow href=http://www.youtube.com/watch?v=2bP9tRhJRTw>www.youtube.com/watch?v=2bP9tRhJRTw</a> russel peters video blah blah. Turtles: <a href=http://turtles.com>turtles.com</a>
In which cases to you need to watch out for Concurrency problems (and use
I have wrote some code to find out of 3 variables witch is the
I watch a lot of tutorials on the web, expesially ASP.NET tutorials - And

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.