• <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中制作一定范围内的均匀间隔数字列表

        Making a list of evenly spaced numbers in a certain range in python(在python中制作一定范围内的均匀间隔数字列表)
          <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中制作一定范围内的均匀间隔数字列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)

                      <tfoot id='OriDX'></tfoot>
                    • <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>
                            <tbody id='OriDX'></tbody>

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