小编Rod*_*phe的帖子

安装python库时,"'cc'以退出状态1失败"错误

像许多其他人一样,我在安装python库时遇到问题(下载为tar,然后提取).

rodolphe-mbp:python-Levenshtein-0.11.2 Rodolphe$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to python_Levenshtein.egg-info/requires.txt
writing python_Levenshtein.egg-info/PKG-INFO
writing namespace_packages to python_Levenshtein.egg-info/namespace_packages.txt
writing top-level names to python_Levenshtein.egg-info/top_level.txt
writing dependency_links to python_Levenshtein.egg-info/dependency_links.txt
writing entry points to python_Levenshtein.egg-info/entry_points.txt
reading manifest file 'python_Levenshtein.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'docs'
warning: no previously-included files matching '*pyc' found anywhere in distribution
warning: no previously-included files matching '.project' found anywhere in distribution
warning: no previously-included files matching '.pydevproject' …
Run Code Online (Sandbox Code Playgroud)

python clang osx-mavericks xcode5.1

36
推荐指数
3
解决办法
5万
查看次数

Python:使用pandas逐列缩放数字

我有一个Pandas数据框'df',其中我想逐列执行一些缩放.

  • 在列'a'中,我需要将最大数字设置为1,将最小数字设置为0,并将所有其他数字相应地进行扩展.
  • 但是,在"b"列中,我需要将最小数字设置为1,将最大数字设置为0,并将所有其他数字相应地进行扩展.

是否有Pandas功能来执行这两个操作?如果没有,numpy肯定会.

    a    b
A   14   103
B   90   107
C   90   110
D   96   114
E   91   114
Run Code Online (Sandbox Code Playgroud)

python pandas

29
推荐指数
4
解决办法
5万
查看次数

如何在ggplot2中设置固定的连续颜色值

我正在绘制大量的图形,我希望它们都具有相同的色标,以便我可以相互比较.这是我的代码:

myPalette <- colorRampPalette(rev(brewer.pal(11, "Spectral")))
print(ggplot(mydata, aes(x= X, y= Y, colour= Z)) + geom_point(alpha=.5,size = 6) + scale_colour_gradientn(colours = myPalette(100)) + ylim(.1,.4) + xlim(1.5,2) + ggtitle(title))
Run Code Online (Sandbox Code Playgroud)

有没有办法设置这个色标?

r ggplot2

21
推荐指数
3
解决办法
3万
查看次数

在Python中快速计算Pareto前沿

我在3D空间中有一组点,我需要从中找到Pareto前沿.执行速度在这里非常重要,并且当我添加测试点时,时间会非常快.

点集看起来像这样:

[[0.3296170319979843, 0.0, 0.44472108843537406], [0.3296170319979843,0.0, 0.44472108843537406], [0.32920760896951373, 0.0, 0.4440408163265306], [0.32920760896951373, 0.0, 0.4440408163265306], [0.33815192743764166, 0.0, 0.44356462585034007]]
Run Code Online (Sandbox Code Playgroud)

现在,我正在使用这个算法:

def dominates(row, candidateRow):
    return sum([row[x] >= candidateRow[x] for x in range(len(row))]) == len(row) 

def simple_cull(inputPoints, dominates):
    paretoPoints = set()
    candidateRowNr = 0
    dominatedPoints = set()
    while True:
        candidateRow = inputPoints[candidateRowNr]
        inputPoints.remove(candidateRow)
        rowNr = 0
        nonDominated = True
        while len(inputPoints) != 0 and rowNr < len(inputPoints):
            row = inputPoints[rowNr]
            if dominates(candidateRow, row):
                # If it is worse on all features remove the row from …
Run Code Online (Sandbox Code Playgroud)

python numpy

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

在Unity3d中更改弹簧关节的静止长度

根据Spring Joint的文档,弹簧的静止长度(弹簧不会试图将它连接的两个物体拉到或推到一起的长度)是两个物体在创建关节时计算的距离.

但是,我希望能够在运行时更改此静止距离,并且文档没有提及有关如何更改长度的任何信息.

无论如何使用Spring Joint实现这一目标?如果没有,如何使用Configurable Joint创建一个具有设定静止长度的弹簧(可在脚本中更改)?

unity-game-engine physx

14
推荐指数
1
解决办法
510
查看次数

在Ggplot2中使用自定义OTF字体

我需要在R中使用自定义字体,即"Archer"和ggplot2.Archer是我系统上安装的otf字体(Mac OSX Yosemite).

这个脚本(在这里找到:在ggplot2中修改字体)不适用于Archer,但适用于其他字体,如Arial.

install.packages("extrafont");library(extrafont)
font_import("Archer")
library(ggplot2)
qplot(1:10)+theme(text=element_text(family="Archer"))
Run Code Online (Sandbox Code Playgroud)

otf字体有什么问题吗?

macos fonts r ggplot2 typeface

9
推荐指数
2
解决办法
2993
查看次数

嵌入新字体到ggplot2,R(mac)中绘图

我一直在尝试将ggplot2图输出为PDF.问题是我一直在为我的图添加异国情调的字体,结果 - 导出的PDF不显示任何文本.

我确保导入我的字体:

library(extrafont)
font_import(pattern = 'Arch')
loadfonts()
Run Code Online (Sandbox Code Playgroud)

在我的ggplot2图放入变量" p" 后,我导出为PDF :

ggsave("myPlot.pdf", plot=p,  width=4, height=6)
embed_fonts("myPlot.pdf", outfile="myPlot_embed.pdf")
Run Code Online (Sandbox Code Playgroud)

然后我得到一个错误说:

GhostScript was not found
Run Code Online (Sandbox Code Playgroud)

但是,这个页面似乎表明在Mac OS上不需要其他步骤(在Windows上有一个额外的步骤):https://github.com/wch/extrafont

我知道自己做错了什么吗?

pdf fonts r ggplot2

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

使用字符串标题将numpy数组保存到csv

我有一个包含浮点数的大型numpy数组,我将其保存为带有np.savetxt的csv文件("myFile.csv",myArray,delimiter =",")

现在,由于数组有很多列而且很难记住它是什么,我想在导出之前向数组中添加一个字符串头.由于numpy不接受float数组中的字符串,有没有一个技巧来完成这个?

[解决方案]感谢Cyborg的建议,我设法安装了Pandas.

import pandas as pd
df = pd.DataFrame(A) # A is a numpy 2d array
df.to_excel("A.xls", header=C,index=False) # C is a list of string corresponding to the title of each column of A
Run Code Online (Sandbox Code Playgroud)

arrays numpy header export-to-csv pandas

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

如何在Mac上使用PyPy?

PyPy的速度承诺让我想尝试一下.不幸的是,我在这个主题上阅读的教程都没有真正帮助我理解基础知识,即如何(简单的步骤):

  • 在Mac上安装PyPy
  • 运行.py脚本

我读了下载,解压并运行pypy myscript.pybin/应该做的伎俩,但没有运气,我至今.这是我得到的:

MyMacbook:bin User$ pypy myscript.py
-bash: pypy: command not found
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我理解PyPy的基本用法吗?

python pypy

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

从RColorBrewer调色板中选取单个颜色作为ggplot2中的scale_colour_manual()值

使用scale_colour_manual(),可以从RColorBrewer中选择特定颜色作为颜色值吗?

例如,在:

scale_colour_manual(breaks=c("A","B","C","D","E"), 
    values=c("green","orange","blue","pink","yellow")) 
Run Code Online (Sandbox Code Playgroud)

我想使用调色板中的第一种颜色scale_colour_brewer(type = "qual", palette = 7)而不是"绿色",然后使用调色板的第四种颜色scale_colour_brewer(type = "qual", palette = 2)而不是"橙色",依此类推.

r ggplot2

6
推荐指数
1
解决办法
6651
查看次数