Python ValueError while dividing array by its own column -


numpy arrays a = [[1, 2, 3, 4], [1, 2, 3, 4 ]] , c = a[:,1]. b should a/c. expecting b [[0.5, 1, 1.5, 2], [0.5, 1, 1.5, 2]] trying same using normal division, or numpy division, error, valueerror: operands not broadcast shapes (2,4) (2,). dividing entire array column in particular array. suggestions? there similar post, no solid answers it.

to make broadcasting possible here add 1 more axis c:

>>> = np.array([[1, 2, 3, 4], [1, 2, 3, 4 ]], dtype=float) >>> c = a[:,1][:, none] >>> a/c array([[ 0.5,  1. ,  1.5,  2. ],        [ 0.5,  1. ,  1.5,  2. ]]) 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -