Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40fd50e

Browse files
author
Åsmund Hjulstad
committed
DOC: Updated docstring for histogram2d as suggested in issue #5538
Also, added unittest for [int, array] combination arguments
1 parent 8cf7c4a commit 40fd50e

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

numpy/lib/tests/test_twodim_base.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,37 @@ def test_empty(self):
265265
a, edge1, edge2 = histogram2d([], [], bins=4)
266266
assert_array_max_ulp(a, np.zeros((4, 4)))
267267

268+
def test_binparameter_combination(self):
269+
x = array(
270+
[0, 0.09207008, 0.64575234, 0.12875982, 0.47390599,
271+
0.59944483, 1])
272+
y = array(
273+
[0, 0.14344267, 0.48988575, 0.30558665, 0.44700682,
274+
0.15886423, 1])
275+
edges = (0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)
276+
H, xe, ye = histogram2d(x, y, (edges, 4))
277+
answer = array(
278+
[[ 2., 0., 0., 0.],
279+
[ 0., 1., 0., 0.],
280+
[ 0., 0., 0., 0.],
281+
[ 0., 0., 0., 0.],
282+
[ 0., 1., 0., 0.],
283+
[ 1., 0., 0., 0.],
284+
[ 0., 1., 0., 0.],
285+
[ 0., 0., 0., 0.],
286+
[ 0., 0., 0., 0.],
287+
[ 0., 0., 0., 1.]])
288+
assert_array_equal(H, answer)
289+
assert_array_equal(ye, array([0., 0.25, 0.5, 0.75, 1]))
290+
H, xe, ye = histogram2d(x, y, (4, edges))
291+
answer = array(
292+
[[ 1., 1., 0., 1., 0., 0., 0., 0., 0., 0.],
293+
[ 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],
294+
[ 0., 1., 0., 0., 1., 0., 0., 0., 0., 0.],
295+
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])
296+
assert_array_equal(H, answer)
297+
assert_array_equal(xe, array([0., 0.25, 0.5, 0.75, 1]))
298+
268299

269300
class TestTri(TestCase):
270301
def test_dtype(self):

numpy/lib/twodim_base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,18 @@ def histogram2d(x, y, bins=10, range=None, normed=False, weights=None):
589589
y : array_like, shape (N,)
590590
An array containing the y coordinates of the points to be
591591
histogrammed.
592-
bins : int or [int, int] or array_like or [array, array], optional
592+
bins : int or array_like or [int, int] or [array, array], optional
593593
The bin specification:
594594
595595
* If int, the number of bins for the two dimensions (nx=ny=bins).
596-
* If [int, int], the number of bins in each dimension
597-
(nx, ny = bins).
598596
* If array_like, the bin edges for the two dimensions
599597
(x_edges=y_edges=bins).
598+
* If [int, int], the number of bins in each dimension
599+
(nx, ny = bins).
600600
* If [array, array], the bin edges in each dimension
601601
(x_edges, y_edges = bins).
602+
* A combination [int, array] or [array, int], where int
603+
is the number of bins and array is the bin edges.
602604
603605
range : array_like, shape(2,2), optional
604606
The leftmost and rightmost edges of the bins along each dimension

0 commit comments

Comments
 (0)