像许多其他人一样,我在安装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) 我有一个Pandas数据框'df',其中我想逐列执行一些缩放.
是否有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) 我正在绘制大量的图形,我希望它们都具有相同的色标,以便我可以相互比较.这是我的代码:
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)
有没有办法设置这个色标?
我在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) 根据Spring Joint的文档,弹簧的静止长度(弹簧不会试图将它连接的两个物体拉到或推到一起的长度)是两个物体在创建关节时计算的距离.
但是,我希望能够在运行时更改此静止距离,并且文档没有提及有关如何更改长度的任何信息.
无论如何使用Spring Joint实现这一目标?如果没有,如何使用Configurable Joint创建一个具有设定静止长度的弹簧(可在脚本中更改)?
我需要在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字体有什么问题吗?
我一直在尝试将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
我知道自己做错了什么吗?
我有一个包含浮点数的大型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) PyPy的速度承诺让我想尝试一下.不幸的是,我在这个主题上阅读的教程都没有真正帮助我理解基础知识,即如何(简单的步骤):
我读了下载,解压并运行pypy myscript.py
从bin/
应该做的伎俩,但没有运气,我至今.这是我得到的:
MyMacbook:bin User$ pypy myscript.py
-bash: pypy: command not found
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我理解PyPy的基本用法吗?
使用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)
而不是"橙色",依此类推.