简体   繁体   中英

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.

我相信要将其传递给多维数组,您将需要将数组方法的参数以数组表示法放置:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM