0

I have four images that I converted to a vector. I'm trying to save those vectors in a numpy array to have a similar structure to the following matrix:

np.array([[0,0,1],
         [0,1,1],
         [1,0,1],
         [1,1,1]])

This is what I did:

import numpy as np
from PIL import Image

image1 = Image.open('cat0.jpg').convert('L')
image_array1 = arr = np.array(image1)
image_array_to_vector1 = image_array1.ravel()

image2 = Image.open('cat1.jpg').convert('L')
image_array2 = arr = np.array(image2)
image_array_to_vector2 = image_array2.ravel()

image3 = Image.open('cat2.jpg').convert('L')
image_array3 = arr = np.array(image3)
image_array_to_vector3 = image_array3.ravel()

image4 = Image.open('dog1.jpg').convert('L')
image_array4 = arr = np.array(image4)
image_array_to_vector4 = image_array4.ravel()

X = np.array(image_array_to_vector1,image_array_to_vector2,image_array_to_vector3,image_array_to_vector4)

I'm however getting the following error:

X = np.array(image_array_to_vector1,image_array_to_vector2,image_array_to_vector3,image_array_to_vector4)
ValueError: only 2 non-keyword arguments accepted

What am I doing wrong? How can I solve this issue?

Thanks.

1
  • 1
    I think you are looking for numpy.vstack(). Commented Dec 27, 2017 at 1:44

1 Answer 1

2

I believe to pass it a multidimension array you would have to need to place the arguments to the array method in array notation:

X = np.array([image_array_to_vector1,image_array_to_vector2,image_array_to_vector3,image_array_to_vector4])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.