Python 使用scipy和numpy对浮点进行排序

Python 使用scipy和numpy对浮点进行排序,python,numpy,scipy,Python,Numpy,Scipy,有人能帮我把一组浮点数排序到不大于10的箱子里吗?我有两个问题,程序读取一组文件并为每个值创建单独的数组。第二,我不确定numpy binning到底是怎么回事 for filename in glob.iglob('*.html'): with open(filename) as f: soup = BeautifulSoup(f) results = [] weight = soup.find('b', text='Shipping

有人能帮我把一组浮点数排序到不大于10的箱子里吗?我有两个问题,程序读取一组文件并为每个值创建单独的数组。第二,我不确定numpy binning到底是怎么回事

for filename in glob.iglob('*.html'):
    with open(filename) as f:
        soup = BeautifulSoup(f)
        results = []

        weight = soup.find('b', text='Shipping Weight:').next_sibling
        title = soup.find("span", id="btAsinTitle")

        results = weight
        import re
        import scipy 
        import numpy as np

        result_str = re.findall(r"[-+]?\d*\.\d+|\d+", results)
        result = float(result_str[0])
        #print result

        array_weight = [result]

        print array_weight

        x = np.array(array_weight)

        bins = np.array([10.0])

        inds = np.digitize(x, bins)

        print inds

回答标题问题,忽略其他问题(请阅读!),这是一个最简单的工作示例

返回

[ 9.29893458  0.88322852  4.9592157   7.33677397  0.20901007  5.77875637
  2.49152666  3.55982666  5.33997896  3.76318862  0.35513614  7.12985682
  2.57747437  4.62240375  8.02503782  5.43143368  6.29290487  2.79342587
  3.11806151  5.79996645]
[4 1 2 3 1 3 1 2 3 2 1 3 2 2 4 3 3 2 2 3]

仔细阅读文档是很有用的,它们告诉你正确的输入和输出

你能把这段代码简化一点吗?我们不需要看到所有漂亮的汤或
re
东西来帮助您排序/装箱浮动。从你的浮点数组开始,然后从那里开始,否则我会有点迷路。注意,把你的导入语句带到循环之外!否则,在该for循环的每次迭代中都会产生开销。
[ 9.29893458  0.88322852  4.9592157   7.33677397  0.20901007  5.77875637
  2.49152666  3.55982666  5.33997896  3.76318862  0.35513614  7.12985682
  2.57747437  4.62240375  8.02503782  5.43143368  6.29290487  2.79342587
  3.11806151  5.79996645]
[4 1 2 3 1 3 1 2 3 2 1 3 2 2 4 3 3 2 2 3]