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

Method test_shuffle

numpy/random/tests/test_generator_mt19937.py:940–965  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

938 assert_equal(actual, desired)
939
940 def test_shuffle(self):
941 # Test lists, arrays (of various dtypes), and multidimensional versions
942 # of both, c-contiguous or not:
943 for conv in [lambda x: np.array([]),
944 lambda x: x,
945 lambda x: np.asarray(x).astype(np.int8),
946 lambda x: np.asarray(x).astype(np.float32),
947 lambda x: np.asarray(x).astype(np.complex64),
948 lambda x: np.asarray(x).astype(object),
949 lambda x: [(i, i) for i in x],
950 lambda x: np.asarray([[i, i] for i in x]),
951 lambda x: np.vstack([x, x]).T,
952 # gh-11442
953 lambda x: (np.asarray([(i, i) for i in x],
954 [("a", int), ("b", int)])
955 .view(np.recarray)),
956 # gh-4270
957 lambda x: np.asarray([(i, i) for i in x],
958 [("a", object, (1,)),
959 ("b", np.int32, (1,))])]:
960 random = Generator(MT19937(self.seed))
961 alist = conv([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
962 random.shuffle(alist)
963 actual = alist
964 desired = conv([4, 1, 9, 8, 0, 5, 3, 6, 2, 7])
965 assert_array_equal(actual, desired)
966
967 def test_shuffle_custom_axis(self):
968 random = Generator(MT19937(self.seed))

Callers

nothing calls this directly

Calls 4

assert_array_equalFunction · 0.90
astypeMethod · 0.80
convFunction · 0.50
viewMethod · 0.45

Tested by

no test coverage detected