'How to calculate secondary diagonals mean in a 2D array?

I want to calculate the mean of each secondary diagonal in the NumPy array. For example, I have this array :

    b=np.array([[1,3,4,2],[6,3,5,1],[7,8,9,12],[5,6,9,3],[8,7,3,2],[4,5,6,9]])

and I want to write a code that the output would be:

    np.array([1, 4.5, 4.6, 5, 6, 8, 3.6, 4, 9])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source