user7867665
user7867665

Reputation: 882

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 ?

Upvotes: 0

Views: 369

Answers (1)

Roberto Trani
Roberto Trani

Reputation: 1227

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

Upvotes: 2

Related Questions