• <legend id='V7ZrL'><style id='V7ZrL'><dir id='V7ZrL'><q id='V7ZrL'></q></dir></style></legend>

      <i id='V7ZrL'><tr id='V7ZrL'><dt id='V7ZrL'><q id='V7ZrL'><span id='V7ZrL'><b id='V7ZrL'><form id='V7ZrL'><ins id='V7ZrL'></ins><ul id='V7ZrL'></ul><sub id='V7ZrL'></sub></form><legend id='V7ZrL'></legend><bdo id='V7ZrL'><pre id='V7ZrL'><center id='V7ZrL'></center></pre></bdo></b><th id='V7ZrL'></th></span></q></dt></tr></i><div id='V7ZrL'><tfoot id='V7ZrL'></tfoot><dl id='V7ZrL'><fieldset id='V7ZrL'></fieldset></dl></div>

      <tfoot id='V7ZrL'></tfoot>

      <small id='V7ZrL'></small><noframes id='V7ZrL'>

          <bdo id='V7ZrL'></bdo><ul id='V7ZrL'></ul>

        在python中制作一定范围内的均匀间隔数字列表

        时间:2023-11-08
          <legend id='BS1oA'><style id='BS1oA'><dir id='BS1oA'><q id='BS1oA'></q></dir></style></legend>
            <tbody id='BS1oA'></tbody>

              <small id='BS1oA'></small><noframes id='BS1oA'>

                • <bdo id='BS1oA'></bdo><ul id='BS1oA'></ul>
                  <tfoot id='BS1oA'></tfoot>
                • <i id='BS1oA'><tr id='BS1oA'><dt id='BS1oA'><q id='BS1oA'><span id='BS1oA'><b id='BS1oA'><form id='BS1oA'><ins id='BS1oA'></ins><ul id='BS1oA'></ul><sub id='BS1oA'></sub></form><legend id='BS1oA'></legend><bdo id='BS1oA'><pre id='BS1oA'><center id='BS1oA'></center></pre></bdo></b><th id='BS1oA'></th></span></q></dt></tr></i><div id='BS1oA'><tfoot id='BS1oA'></tfoot><dl id='BS1oA'><fieldset id='BS1oA'></fieldset></dl></div>
                  本文介绍了在python中制作一定范围内的均匀间隔数字列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  What is a pythonic way of making list of arbitrary length containing evenly spaced numbers (not just whole integers) between given bounds? For instance:

                  my_func(0,5,10) # ( lower_bound , upper_bound , length )
                  # [ 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 ] 
                  

                  Note the Range() function only deals with integers. And this:

                  def my_func(low,up,leng):
                      list = []
                      step = (up - low) / float(leng)
                      for i in range(leng):
                          list.append(low)
                          low = low + step
                      return list
                  

                  seems too complicated. Any ideas?

                  解决方案

                  Given numpy, you could use linspace:

                  Including the right endpoint (5):

                  In [46]: import numpy as np
                  In [47]: np.linspace(0,5,10)
                  Out[47]: 
                  array([ 0.        ,  0.55555556,  1.11111111,  1.66666667,  2.22222222,
                          2.77777778,  3.33333333,  3.88888889,  4.44444444,  5.        ])
                  

                  Excluding the right endpoint:

                  In [48]: np.linspace(0,5,10,endpoint=False)
                  Out[48]: array([ 0. ,  0.5,  1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5])
                  

                  这篇关于在python中制作一定范围内的均匀间隔数字列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python - 完美数搜索的优化 下一篇:python中range()函数的返回值是多少?

                  相关文章

                    <tfoot id='OriDX'></tfoot>
                  1. <small id='OriDX'></small><noframes id='OriDX'>

                      <i id='OriDX'><tr id='OriDX'><dt id='OriDX'><q id='OriDX'><span id='OriDX'><b id='OriDX'><form id='OriDX'><ins id='OriDX'></ins><ul id='OriDX'></ul><sub id='OriDX'></sub></form><legend id='OriDX'></legend><bdo id='OriDX'><pre id='OriDX'><center id='OriDX'></center></pre></bdo></b><th id='OriDX'></th></span></q></dt></tr></i><div id='OriDX'><tfoot id='OriDX'></tfoot><dl id='OriDX'><fieldset id='OriDX'></fieldset></dl></div>

                    1. <legend id='OriDX'><style id='OriDX'><dir id='OriDX'><q id='OriDX'></q></dir></style></legend>
                      • <bdo id='OriDX'></bdo><ul id='OriDX'></ul>