将结构化的Numpy数组转换为普通数组

时间:2019-06-07 20:16:42

标签: python numpy opencl

我有一个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)

我正在寻找这个答案:Convert structured array to regular NumPy array

0 个答案:

没有答案