Simplicity
Simplicity

Reputation: 48916

Saving vectorized images to a numpy array

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.

Upvotes: 0

Views: 292

Answers (1)

LhasaDad
LhasaDad

Reputation: 2133

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])

Upvotes: 2

Related Questions