MCPcopy Create free account
hub / github.com/numpy/numpy / test_diag_indices

Function test_diag_indices

numpy/lib/tests/test_index_tricks.py:505–530  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

503
504
505def 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
533class TestDiagIndicesFrom:

Callers

nothing calls this directly

Calls 2

diag_indicesFunction · 0.90
assert_array_equalFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…