How can I put all the values of my matrix ckpot_p_shell_matrix into just 1 whole list? I want the values in a list so I can do a histogram plot of the values.
ckpot_p_shell_matrix is a numpy.ndarray 2D matrix that has a shape (28, 108) containing values between 0 ~ 10.
>>> type(ckpot_p_shell_matrix)
numpy.ndarray
>>> ckpot_p_shell_matrix.shape
(28, 108)
>>> ckpot_p_shell_matrix
array([[0.2407545, 0.3681921, 0.5176657, ..., 2.9999998, 1.5 ,
2.9316723],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
...,
[3.5468006, 2.0326045, 2.42928 , ..., 4.5 , 5.25 ,
3.5797157],
[0.7088 , 1.5522 , 1.0474 , ..., 4. , 3. ,
3.95444 ],
[5.2912 , 4.4478 , 4.9526 , ..., 6. , 7. ,
6.04556 ]])
>Solution :
Use numpy .flatten()
import numpy as np
ckpot_p_shell_matrix = np.array([[0.2407545, 0.3681921, 0.5176657, ..., 2.9999998, 1.5 ,
2.9316723],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
...,
[3.5468006, 2.0326045, 2.42928 , ..., 4.5 , 5.25 ,
3.5797157],
[0.7088 , 1.5522 , 1.0474 , ..., 4. , 3. ,
3.95444 ],
[5.2912 , 4.4478 , 4.9526 , ..., 6. , 7. ,
6.04556 ]])
print(ckpot_p_shell_matrix.flatten())
Output:
np.array([[0.2407545, 0.3681921, 0.5176657, ..., 2.9999998, 1.5 ,