How to use 'numpy array slicing' in Python

Every line of 'numpy array slicing' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
154def test_RaggedArray_slicing(self):
155 src = np.array(range(60))
156 a = ra.RaggedArray(array=src, lengths=[10, 20, 30])
157
158 assert_array_equal(a[:].flatten(), src)
159 assert_array_equal(a[0:2].flatten(), src[0:30])
160 assert_array_equal(a[1:].flatten(), src[10:])
161
162 assert_array_equal(a[:, 0:5].flatten(), np.concatenate((src[0:5],
163 src[10:15],
164 src[30:35])))
165
166 assert_is(type(a[[0, 1]]), type(a))
167 assert_is(type(a[0]), type(src))
168 assert_is(type(a[[0]]), type(a))
169
170 assert_array_equal(a[0, 5:10], src[5:10])
171 assert_array_equal(a[-1, 5:10], src[35:40])
172
173 assert_array_equal(a[2, 10:15:2], src[40:45:2])
174 assert_array_equal(a[0, ::-1], src[9::-1])
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets