我有一个dtype.names
为的numpy数组:
('s0', 's1', 's2', 's3')
我应该采取什么步骤将numpy数组dtype
还原为np.float32?
我从以下位置获取numpy数组(“ s0”,“ s1”,“ s2”,“ s3”):
import pyopencl as cl
import pyopencl.array as cl_array
import numpy as np
from scipy.misc import imread, imsave
import math
import os
import PIL.Image
import cv2
os.environ['PYOPENCL_COMPILER_OUTPUT'] = '1'
#produces numpy array of the structures
# -> ('s0', 's1', 's2', 's3') and shape (image_width,image_height, image_depth).
def process_image(path_to_image, padding):
rgb_image = PIL.Image.open(path_to_image)
rgba_image = rgb_image.convert('RGBA')
im_src = np.array(rgba_image).astype(dtype=np.float32)
print(im_src.shape)
return im_src.astype(dtype=cl_array.vec.float4)
dtype=cl_array.vec.float4
将4 np.float32
捆绑为(np.float32,np.float32,np.float32,np.float32)
image_depth
是4:
我尝试过:
vector_float4= process_image('image.jpg',0)
result = np.array(vector_float4.tolist())
result
的形状为(width, height, 4, 4)
。我期望(width, height, 4)
。