I have a numpy array with the dtype.names
as:
('s0', 's1', 's2', 's3')
What steps would I follow to revert the numpy array dtype
to np.float32?
I obtain the numpy array ('s0', 's1', 's2', 's3') from:
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
bundles 4 np.float32
into (np.float32,np.float32,np.float32,np.float32)
The image_depth
is 4:
I tried this:
vector_float4= process_image('image.jpg',0)
result = np.array(vector_float4.tolist())
result
has a shape of (width, height, 4, 4)
. I expected (width, height, 4)
.
I am looking at this answer: Convert structured array to regular NumPy array