亲宝软件园·资讯

展开

python 实现生成均匀分布的点

人气:0

如下所示:

import numpy as np
print(np.linspace(-100,100,201)

np.linspace(),起始位置,终止位置,中间包括0,一共要201个点

因为-100,100共201个点,包括两边的数据,也就是数学上的闭区间。

结果:

-100. -99. -98. -97. -96. -95. -94. -93. -92. -91. -90. -89.
 -88. -87. -86. -85. -84. -83. -82. -81. -80. -79. -78. -77.
 -76. -75. -74. -73. -72. -71. -70. -69. -68. -67. -66. -65.
 -64. -63. -62. -61. -60. -59. -58. -57. -56. -55. -54. -53.
 -52. -51. -50. -49. -48. -47. -46. -45. -44. -43. -42. -41.
 -40. -39. -38. -37. -36. -35. -34. -33. -32. -31. -30. -29.
 -28. -27. -26. -25. -24. -23. -22. -21. -20. -19. -18. -17.
 -16. -15. -14. -13. -12. -11. -10.  -9.  -8.  -7.  -6.  -5.
  -4.  -3.  -2.  -1.  0.  1.  2.  3.  4.  5.  6.  7.
  8.  9.  10.  11.  12.  13.  14.  15.  16.  17.  18.  19.
  20.  21.  22.  23.  24.  25.  26.  27.  28.  29.  30.  31.
  32.  33.  34.  35.  36.  37.  38.  39.  40.  41.  42.  43.
  44.  45.  46.  47.  48.  49.  50.  51.  52.  53.  54.  55.
  56.  57.  58.  59.  60.  61.  62.  63.  64.  65.  66.  67.
  68.  69.  70.  71.  72.  73.  74.  75.  76.  77.  78.  79.
  80.  81.  82.  83.  84.  85.  86.  87.  88.  89.  90.  91.
  92.  93.  94.  95.  96.  97.  98.  99. 100.]

但 如果 你没有计算两个数之间有多少点。

例如下意识的在(-100,100,200)之间取200个点,情况和你想的不一样:

结果:

[-100.     -98.99497487 -97.98994975 -96.98492462 -95.9798995
 -94.97487437 -93.96984925 -92.96482412 -91.95979899 -90.95477387
 -89.94974874 -88.94472362 -87.93969849 -86.93467337 -85.92964824
 -84.92462312 -83.91959799 -82.91457286 -81.90954774 -80.90452261
 -79.89949749 -78.89447236 -77.88944724 -76.88442211 -75.87939698
 -74.87437186 -73.86934673 -72.86432161 -71.85929648 -70.85427136
 -69.84924623 -68.84422111 -67.83919598 -66.83417085 -65.82914573
 -64.8241206  -63.81909548 -62.81407035 -61.80904523 -60.8040201
 -59.79899497 -58.79396985 -57.78894472 -56.7839196  -55.77889447
 -54.77386935 -53.76884422 -52.7638191  -51.75879397 -50.75376884
 -49.74874372 -48.74371859 -47.73869347 -46.73366834 -45.72864322
 -44.72361809 -43.71859296 -42.71356784 -41.70854271 -40.70351759
 -39.69849246 -38.69346734 -37.68844221 -36.68341709 -35.67839196
 -34.67336683 -33.66834171 -32.66331658 -31.65829146 -30.65326633
 -29.64824121 -28.64321608 -27.63819095 -26.63316583 -25.6281407
 -24.62311558 -23.61809045 -22.61306533 -21.6080402  -20.60301508
 -19.59798995 -18.59296482 -17.5879397  -16.58291457 -15.57788945
 -14.57286432 -13.5678392  -12.56281407 -11.55778894 -10.55276382
  -9.54773869  -8.54271357  -7.53768844  -6.53266332  -5.52763819
  -4.52261307  -3.51758794  -2.51256281  -1.50753769  -0.50251256
  0.50251256  1.50753769  2.51256281  3.51758794  4.52261307
  5.52763819  6.53266332  7.53768844  8.54271357  9.54773869
  10.55276382  11.55778894  12.56281407  13.5678392  14.57286432
  15.57788945  16.58291457  17.5879397  18.59296482  19.59798995
  20.60301508  21.6080402  22.61306533  23.61809045  24.62311558
  25.6281407  26.63316583  27.63819095  28.64321608  29.64824121
  30.65326633  31.65829146  32.66331658  33.66834171  34.67336683
  35.67839196  36.68341709  37.68844221  38.69346734  39.69849246
  40.70351759  41.70854271  42.71356784  43.71859296  44.72361809
  45.72864322  46.73366834  47.73869347  48.74371859  49.74874372
  50.75376884  51.75879397  52.7638191  53.76884422  54.77386935
  55.77889447  56.7839196  57.78894472  58.79396985  59.79899497
  60.8040201  61.80904523  62.81407035  63.81909548  64.8241206
  65.82914573  66.83417085  67.83919598  68.84422111  69.84924623
  70.85427136  71.85929648  72.86432161  73.86934673  74.87437186
  75.87939698  76.88442211  77.88944724  78.89447236  79.89949749
  80.90452261  81.90954774  82.91457286  83.91959799  84.92462312
  85.92964824  86.93467337  87.93969849  88.94472362  89.94974874
  90.95477387  91.95979899  92.96482412  93.96984925  94.97487437
  95.9798995  96.98492462  97.98994975  98.99497487 100.    ]

所以,在使用这个函数时,要仔细考虑两端的数据,还有你需要多少点。

以上这篇python 实现生成均匀分布的点就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论