Last answered:

01 Oct 2024

Posted on:

01 Oct 2024

0

2-D histogram: Density matrix values ​​in their correct position.

Hi Viktor, you indicated in the lesson on Histograms in NumPy (part 2) that in the density array returned by the np.histogram2d() function there is a slight rotation because the rows of said array correspond to the X bins and the columns to the Y bins. In other words, the rows are swapped with the columns with respect to a visual representation.
Using Python and Numpy features I wrote a line of code that repositions the values ​​of the density matrix so that it corresponds directly, without rotations, with its graphical representation in the X, Y coordinate plane.

The code is as follows,
             np.array(list(map(lambda row: row[::-1], dm))).T
dm, is de density array. 
dm = np.histogram2d(matrix_A[0], matrix_A[1], bins=4)[0]    
And I ask you about it if you agree with me that the resulting matrix in this case is the density array that fully corresponds to its graphical representation in the X, Y plane and that this matrix is ​​practically also giving us the visual representation of the corresponding 2-D histogram
1 answers ( 0 marked as helpful)
Posted on:

01 Oct 2024

0
I added some graphs and, at least for the lesson example, I see that the graph clearly looks like the repositioned value density matrix:

Submit an answer