Search code examples
pythonpandasnumpyhistogram2d

numpy 2D Histogram


When I run:

hist_2d_i = np.histogram2d(df.feature1.iloc[0], df.feature2.iloc[0], bins=\
[binsx, binsy],weights=df.weights.iloc[0])

I get an error: The dimension of bins must be equal to the dimension of the sample x.

But if I run:

hist_2d_i = np.histogram2d(df.feature1.iloc[0:1], df.feature2.iloc[0:1], bins=\
[binsx, binsy],weights=df.weights.iloc[0:1])

It works as expected. What is the difference?

The index runs through the number of samples in the pandas dataframe dataset.

isn't [0] == [0:1] as index ?


Solution

  • [0] is the first element of an array, while [0:1] is an array containing only the first element.