Pregunta

Why does the following code not produce the expected assignment?

A = np.array([[ 9.,  2.,  7.], [ 3.,  3.,  1.], [ 4.,  1.,  6.]])
L = np.zeros([3,3])
i = range(1,3)
L[i][:,[0]] = A[i][:,[0]] / A[0,0]

L continues to contain all zeros. How do I produce what I expect to see (i.e. [[ 0., 0., 0.], [ .333, 0., 0.], [ .444, 0., 0.]])?

¿Fue útil?

Solución

You should do direct indexing L[i,0]=A[i,0]/A[0,0], otherwise you are working on a view rather than then a slice of the original array.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top