I want to plot a histogram of an array A
which will show me the distribution of all the values. But I am getting an error.
import numpy as np
A=np.array([[1.83221749e-01],
[1.97088986e-03] # <- missing comma here
[1.97088986e-03],
[8.50798103e-03],
开发者_运维百科 [2.53104351e-01],
[2.02513388e-03],
[1.93131808e-03],
[4.12731231e-03],
[1.11217813e-02],
[3.59568196e-03]])
B=np.histogram(A)
The error is
in line 9, in <module>
[1.97088986e-03]
TypeError: list indices must be integers or slices, not float
It appears a comma was omitted from the array. After fixing it you can use plt.bar
:
plt.bar(np.arange(len(A)),A)
plt.show()
精彩评论