Files
Obsidian-Main/20.01. Programming/numpy/numpy - 同樣順序打亂多個array.md

11 lines
316 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
如果多個array的順序有相關性我們要用同樣的順序來打亂他們可以用以下方法
```python
array1 = np.array([[1, 1], [2, 2], [3, 3]])
array2 = np.array([1, 2, 3])
shuffler = np.random.permutation(len(array1))
array1_shuffled = array1[shuffler]
array2_shuffled = array2[shuffler]
```