I have a list of list of tuples:
X = [[(0.5, 0.5, 0.5), (1.0, 1.0, 1.0)], [(0.5, 0.5, 0.52), (1.0, 1.0, 1.0)], [(0.5, 0.52, 0.52), (1.0, 1.0, 1.0)], [(0.52, 0.52, 0.52), (1.0, 1.0, 1.0)], [(0.52, 0.52, 0.52), (1.0, 1.0, 1.0)]]
and would like to convert it to a 2D numpy array. I tried the following but didn't work. I just want to make sure the new transformed 2D keeps the same shape and structure of X. Please help me , thanks a lot.
import numpy as np
X = [[(0.5, 0.5, 0.5), (1.0, 1.0, 1.0)], [(0.5, 0.5, 0.52), (1.0, 1.0, 1.0)], [(0.5, 0.52, 0.52), (1.0, 1.0, 1.0)], [(0.52, 0.52, 0.52), (1.0, 1.0, 1.0)], [(0.52, 0.52, 0.52), (1.0, 1.0, 1.0)]]
np.asarray([sublist for sublist in X])
Expected result would be:
[[ 0.5 , 0.5 , 0.5 ],
[ 1. , 1. , 1. ]],
[[ 0.5 , 0.5 , 0.52],
[ 1. , 1. , 1. ]],
[[ 0.5 , 0.52, 0.52],
[ 1. , 1. , 1. ]],
[[ 0.52, 0.52, 0.52],
[ 1. , 1. , 1. ]],
[[ 0.52, 0.52, 0.52],
[ 1. , 1. , 1. ]]