()
| 503 | |
| 504 | |
| 505 | def test_diag_indices(): |
| 506 | di = diag_indices(4) |
| 507 | a = np.array([[1, 2, 3, 4], |
| 508 | [5, 6, 7, 8], |
| 509 | [9, 10, 11, 12], |
| 510 | [13, 14, 15, 16]]) |
| 511 | a[di] = 100 |
| 512 | assert_array_equal( |
| 513 | a, np.array([[100, 2, 3, 4], |
| 514 | [5, 100, 7, 8], |
| 515 | [9, 10, 100, 12], |
| 516 | [13, 14, 15, 100]]) |
| 517 | ) |
| 518 | |
| 519 | # Now, we create indices to manipulate a 3-d array: |
| 520 | d3 = diag_indices(2, 3) |
| 521 | |
| 522 | # And use it to set the diagonal of a zeros array to 1: |
| 523 | a = np.zeros((2, 2, 2), int) |
| 524 | a[d3] = 1 |
| 525 | assert_array_equal( |
| 526 | a, np.array([[[1, 0], |
| 527 | [0, 0]], |
| 528 | [[0, 0], |
| 529 | [0, 1]]]) |
| 530 | ) |
| 531 | |
| 532 | |
| 533 | class TestDiagIndicesFrom: |
nothing calls this directly
no test coverage detected
searching dependent graphs…