PYTHON
python numpy array to list
# Basic syntax:
numpy_array.tolist()
# Example usage:
your_array = np.array([[1, 2, 3], [4, 5, 6]])
your_array
--> array([[1, 2, 3],
[4, 5, 6]])
your_array.tolist()
--> [[1, 2, 3], [4, 5, 6]]
np.array to list
>>> a = np.array([1, 2])
>>> list(a)
[1, 2]
>>> a.tolist()
[1, 2]
convert list to numpy array
import numpy as np
npa = np.asarray(Lists, dtype=np.float32)
np array to list
# make np array
np_arr = np.array(['a','b','c'])
# np array to list
py_list = np_arr.tolist()
print(py_list)
# output: ['a','b','c']
python convert list of lists to array
# Basic syntax:
numpy.array(list_of_lists)
# Example usage:
import numpy as np
list_of_lists = [[1, 2, 3], [4, 5, 6]] # Create list of lists
your_array = np.array(list_of_lists) # Convert list of lists to array
your_array
--> array([[1, 2, 3],
[4, 5, 6]])
convert list of lists to numpy array matrix python
x=[[1,2],[1,2,3],[1]]
y=numpy.array([numpy.array(xi) for xi in x])
type(y)
# <type 'numpy.ndarray'>
type(y[0])
# <type 'numpy.ndarray'>
list of list to numpy array
>>> lists = [[1, 2], [3, 4]]
>>> np.array(lists)
array([[1, 2],
[3, 4]])
list of array to array numpy
np.concatenate( list_of_array, axis=0 )