小编Mik*_*son的帖子

py2exe 64位python 2.7安装

是否有一个用于64位python 2.7的py2exe 64位的pip安装?32位py2exe对我不起作用,但是当我尝试安装64位版本时,我一直遇到异常.我从这个站点下载了python 2.7的64位py2exe:http://www.lfd.uci.edu/~gohlke/pythonlibs/#py2exe但是无法安装它

我使用python -m pip install py2exe得到的错误:

Runtime Error: This package requires Python 3.3 or later
Command "python setup.py egg_info" failed with error code 1
Run Code Online (Sandbox Code Playgroud)

注意:以下适用于32位,但我需要64位

pip install http://sourceforge.net/projects/py2exe/files/latest/download?source=files 
Run Code Online (Sandbox Code Playgroud)

我正在运行64位python 2.7,我正在尝试安装64位py2exe

任何简单的pip安装吗?

python executable py2exe python-2.7

7
推荐指数
1
解决办法
1万
查看次数

m来自上三角矩阵的最小值,其索引为元组列表

我有一个np.ndarray如下:

[[ inf   1.   3.   2.   1.]
 [ inf  inf   2.   3.   2.]
 [ inf  inf  inf   5.   4.]
 [ inf  inf  inf  inf   1.]
 [ inf  inf  inf  inf  inf]]
Run Code Online (Sandbox Code Playgroud)

有没有办法获得该nd数组中m个最小项的索引和值?所以,如果我想要4个最小的那个

[(0,1,1),(0,4,1),(3,4,1),(0,3,2)] 
Run Code Online (Sandbox Code Playgroud)

其中(row,col,val)是上面的符号.

如果有多个值,则只需随机选择其中一个值.例如,有3个,然后下一个最小值是2,但(0,3,2),(1,2,2),(1,4,2)都是可能的选择.

本质上,我可以有效地从上三角矩阵中提取该格式的k个最小值(矩阵比上面的例子大得多).我尝试使用方形,最小的方法展平它,但是我很难将索引和值对齐.谢谢!

python arrays numpy min pandas

5
推荐指数
1
解决办法
259
查看次数

Find closest k points for every point in row of numpy array

I have a np array, X that is size 1000 x 1000 where each element is a real number. I want to find the 5 closest points for every point in each row of this np array. Here the distance metric can just be abs(x-y). I have tried to do

for i in range(X.shape[0]):
    knn = NearestNeighbors(n_neighbors=5)
    knn.fit(X[i])
    for j in range(X.shape[1])
        d = knn.kneighbors(X[i,j], return_distance=False)
Run Code Online (Sandbox Code Playgroud)

However, this does not work for me and I am not sure how efficient …

python sorting numpy knn

5
推荐指数
1
解决办法
5384
查看次数

pandas在数据帧中的聚合计数

我有一个DataFrame,我正在使用.aggregate({'col1': np.sum}),这将执行值的总和col1并将它们聚合在一起.是否有可能进行计数.aggregate({'col1': some count function here})

indexing counting dataframe pandas

2
推荐指数
1
解决办法
6598
查看次数

数据框到按键分组的元组列表的字典

我有一个数据框 df ,如下所示:

        a    b    c    d
0       8    xx   17   1.0  
1       8    xy   19   1.0 
2       8    zz   13   0.0
3       9    tt   8    5.0
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个字典,其中包含一个包含元组列表的键,如下所示:

{8:[(17,1.0),(19,1.0),(13,0.0)], 9:[(8,5.0)]} 
Run Code Online (Sandbox Code Playgroud)

这里,键来自 a 列,元组列表是键为 a 的 c 列和 d 列。我也将其应用于其他数据集并尝试过

df_new = df.groupby(['a'])[['c','d']).apply(lambda x: [tuple(x) for x in x.values])
Run Code Online (Sandbox Code Playgroud)

但是,我不断收到错误

raise TypeError('Series.name must be a hashable type')
TypeError: Series.name must be a hashable type
Run Code Online (Sandbox Code Playgroud)

我尝试删除 groupby 中的 ['a'] 并将其保留为 'a',如下所示:

df_new = df.groupby('a')[['c','d']).apply(lambda x: [tuple(x) for x in x.values])
Run Code Online (Sandbox Code Playgroud)

但是,我收到相同的以下错误:

raise …
Run Code Online (Sandbox Code Playgroud)

python dictionary dataframe pandas

2
推荐指数
1
解决办法
1871
查看次数

根据元组中的索引删除重复的元组值

有没有办法根据元组中的索引删除重复的元组.说我有

[(0, 4, 1.0), (1, 4, 1.0), (3, 4, 1.0), (0, 3, 2.0), (1, 3, 2.0), (0, 2, 3.0), (1, 2, 3.0), (2, 4, 4.0), (2, 3, 5.0), (0, 1, inf)]
Run Code Online (Sandbox Code Playgroud)

我可以随机保留一个元组,其中每个副本在索引2处具有相同的值吗?

因此,有3个元组在索引2处具有值1.0,两个元组在索引2处具有值2.0,一个在索引2处具有值3,依此类推.

因此,(0,4,1.0)可以从索引2处的值1.0中随机选择,并且(1,3,2.0)可以从索引2处的值2.0中随机选择.说,(1,2,3.0)是从索引2处的值3.0中随机选择.然后,我的列表看起来像

[(0, 4, 1.0),(1, 3, 2.0), (1, 2, 3.0), (2, 4, 4.0), (2, 3, 5.0), (0, 1, inf)]
Run Code Online (Sandbox Code Playgroud)

我从来没有遇到过这样或者至少有效的功能.

python random tuples list duplicates

2
推荐指数
1
解决办法
439
查看次数

到 (row,col,distance) 列表的距离的 Numpy 数组

我有一个 nd 数组,如下所示:

[[ 0.          1.73205081  6.40312424  7.21110255  2.44948974]
 [ 1.73205081  0.          5.09901951  5.91607978  1.        ]
 [ 6.40312424  5.09901951  0.          1.          4.35889894]
 [ 7.21110255  5.91607978  1.          0.          5.09901951]
 [ 2.44948974  1.          4.35889894  5.09901951  0.        ]]
Run Code Online (Sandbox Code Playgroud)

该数组中的每个元素都是一个距离,我需要将其转换为包含行、列、距离的列表,如下所示:

l = [(0,0,0),(0,1, 1.73205081),(0,2, 6.40312424),...,(1,0, 1.73205081),(1,1,0),...,(4,4,0)] 
Run Code Online (Sandbox Code Playgroud)

此外,删除对角线元素会很酷,而且元素 (j,i) 因为 (i,j) 已经存在。本质上,是否可以只取它的顶部三角矩阵?

这是否可以有效地完成(没有很多循环)?我用 squareform 创建了这个数组,但找不到任何文档来执行此操作。

python numpy scipy python-3.x pdist

0
推荐指数
1
解决办法
305
查看次数

在Python中查找列表中的5个最小数字

我有一个名单列表,x和一个与名称对应的分数列表y.

x = {a,b,c,d,e,f,g,h,i,j,k} 
y= {8,8,15,13,12,17,18,12,14,14} 
Run Code Online (Sandbox Code Playgroud)

所以,a得分为8,b得分为8,c得分为15,......,k得分为14

我想从列表中找到5个最小的分数,y,并得到他们的名字,并打印出类似于以下内容:

前5名得分最低:

a : 8
b : 8 
e : 12
h : 12 
d : 13
Run Code Online (Sandbox Code Playgroud)

目前,我正在创建列表的副本,然后使用pop来减少列表,但是它给了我不正确的分数名称.但是,当我为max5值创建列表时,使用相同的方法一切都很好.我不确定一个允许我在python中执行此操作的函数.这只是我的问题的一个例子,我的真正问题涉及商店位置以及我从一个函数计算的那些商店的分数,但我想获得前5名最高分和5分最低分.有没有人有这个有效的解决方案?

python sorting max minimum

-2
推荐指数
1
解决办法
3825
查看次数