I am trying to extract the values from a numpy array and place the individual entries into a list.
For example, if I have the following list:
import numpy as np
x = 1
problem_variable = np.array(['a', 'b'], dtype='<U9')
z = 2
mylist = [x, problem_variable , z]
# [1, array(['a', 'b'], dtype='<U9'), 2]
How do I get the result
[1, 'a', 'b', 2]
I do not know the length of problem_variable
before hand so cannot hard code problem_variable[0]
, problem_variable[1]
etc.
The following does what I want but I am sure that I am missing the appropriate way to break the array apart. Thanks.
result = []
result.append(x)
for i in problem_variable: result.append(i)
result.append(z)