numpy - 图1
© getcodify.com

由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

np array

np arry to list

  1. import numpy as np
  2. List = arry.tolist()

Create a list

  1. print(np.linspace(0, 100, 51))
  1. [ 0. 2. 4. 6. 8. 10. 12. 14. 16. 18. 20. 22. 24. 26.
  2. 28. 30. 32. 34. 36. 38. 40. 42. 44. 46. 48. 50. 52. 54.
  3. 56. 58. 60. 62. 64. 66. 68. 70. 72. 74. 76. 78. 80. 82.
  4. 84. 86. 88. 90. 92. 94. 96. 98. 100.]

np arrary caculating

np.arrary sum()

  1. np.sum(array1-array2)

np arrary append

append

  1. np.append(np1, np2,axis=0)

Reduce Dimension

  1. x = np.array([[1, 2],[3, 4]])
  2. print(np.ravel(x))
  3. print(np.ravel(x,'F'))

Locating (argwhere)

  1. arr = np.random.randint(0,10, (3,4))
  2. index = np.argwhere(arr < 5)
  3. index2 = np.where(arr < 5)
  4. >>> index
  5. array([[0, 2],
  6. [0, 3],
  7. [1, 1],
  8. [2, 0],
  9. [2, 3]])
  10. >>> index2
  11. (array([0, 0, 1, 2, 2]), array([2, 3, 1, 0, 3]))

Axis

Axis flip / swap

  1. frame2 = frame.swapaxes(0,1)
  2. frame.shape
  3. frame2.shape
  1. (360, 480, 3)
  2. (480, 360, 3)

Replace

  1. arr[arr > 255] = x

Enjoy~

本文由Python腳本GitHub/語雀自動更新

由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

GitHub: Karobben
Blog:Karobben
BiliBili:史上最不正經的生物狗