我正在尝试在 Python 2.4.4 的 .tex 文件上运行 pdflatex。子进程(在 Mac 上):
import subprocess
subprocess.Popen(["pdflatex", "fullpathtotexfile"], shell=True)
Run Code Online (Sandbox Code Playgroud)
这实际上什么也不做。但是,我可以在终端中运行“pdflatex fullpathtotexfile”而不会出现问题,生成 pdf。我缺少什么?
[编辑] 正如其中一个答案所建议的,我尝试过:
return_value = subprocess.call(['pdflatex', '/Users/Benjamin/Desktop/directory/ON.tex'], shell =False)
Run Code Online (Sandbox Code Playgroud)
失败并显示:
Traceback (most recent call last):
File "/Users/Benjamin/Desktop/directory/generate_tex_files_v3.py", line 285, in -toplevel-
return_value = subprocess.call(['pdflatex', '/Users/Benjamin/Desktop/directory/ON.tex'], shell =False)
File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/subprocess.py", line 413, in call
return Popen(*args, **kwargs).wait()
File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/subprocess.py", line 543, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/subprocess.py", line 975, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
该文件确实存在,我可以pdflatex /Users/Benjamin/Desktop/directory/ON.tex在终端中运行。请注意, …
我已将 shapefile 读入 aGeoDataFrame并对其进行了一些修改:
import geopandas as gpd
# Read shapefile into geodataframe
geodf = gpd.read_file("shapefile.shp")
# Do some "pandas-like" modifications to shapefile
geodf = modify_geodf(geodf)
Run Code Online (Sandbox Code Playgroud)
但是,我还想osgeo.ogr在其上应用模块的一些功能:
from osgeo import ogr
# Read shapefile into ogr DataSource
ds=ogr.Open("shapefile.shp")
# Do some "gdal/ogr-like" modifications to shapefile
ds = modify_ds(ds)
Run Code Online (Sandbox Code Playgroud)
问题:有什么方法可以直接使用或转换已在内存中的 shapefile,目前采用 GeoDataFrame 的形式osgeo.ogr.DataSource?
到目前为止,我这样做的方法是将 GeoDataFrame 保存到文件中to_file(),然后osgeo.ogr.Open()再次保存,但这对我来说似乎有些多余。
我正在尝试使用 binder beta 在 Github 上共享我的代码。活页夹生成一个环境,但是它在导入 numpy 库时生成错误。错误是“ModuleNotFoundError: No module named 'numpy'” 我该如何解决这个问题?
有没有一种简单的方法可以让 LaTeX url 以斜体显示,即emph{\url{http://www.stackoverflow.com}}?仅供参考,我之前也使用过 \urlstyle{same} ,这使样式看起来像文档默认样式,但我不想将文档默认设置为斜体。
我在其中一个字段中读取了带有"3:29"的csv文件(不带引号).这是一个因素.如何将其转换为数字向量,例如c(3:29)?我尝试了as.vector(),但这给出了一个字符串向量"3,4,5,6 ... 29"(带引号,仍为字符类).
编辑答案需要适用于更一般的形式,例如,列可以包含3:6,7,9:11,需要转换为等效的c(3:6,7,9:11).
我正在实现一些卫星图像滤波器,从一个称为增强型Lee滤波器开始.图像很容易达到5000x5000像素甚至更多.我当前的实现是内存耗尽,试图计算那些大型数组上的过滤器(请注意,移动平均值和移动stddev过滤器可以一次运行).主要困难是为了返回最终过滤的数组,必须保留在内存中的数组的数量.在这个问题中,我请求帮助改进块处理函数,但我的问题是:有没有办法改进这段代码,这样我就不需要使用块处理了?
def moving_average(Ic, filtsize):
Im = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(Ic, filtsize, output=Im)
return Im
def moving_stddev(Ic, filtsize):
Im = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(Ic, filtsize, output=Im)
S = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(((Ic-Im) ** 2), filtsize, output=S)
return numpy.sqrt(S)
def enh_lee(Ic, filtsize, nlooks, dfactor):
# Implementation based on PCI Geomatica's FELEE function documentation
Ci = moving_stddev(Ic, filtsize) / moving_average(Ic, filtsize) #1st array in memory
Cu = numpy.sqrt(1 / nlooks) #scalar
Cmax = numpy.sqrt(1 + (2 * nlooks)) #scalar
W = numpy.exp(-dfactor * …Run Code Online (Sandbox Code Playgroud) 当比较scipy(0.9.0)和matplotlib(1.0.1)Delaunay三角测量程序时,我注意到一个无法解释的行为.我的点是存储在的UTM坐标numpy.array([[easting, northing], [easting, northing], [easting, northing]]).Scipy的边缘缺少一些我的观点,而matplotlib就在那里.有没有修复,或者我做错了什么?
import scipy
import numpy
from scipy.spatial import Delaunay
import matplotlib.delaunay
def delaunay_edges(points):
d = scipy.spatial.Delaunay(points)
s = d.vertices
return numpy.vstack((s[:,:2], s[:,1:], s[:,::-2]))
def delaunay_edges_matplotlib(points):
cens, edges, tri, neig = matplotlib.delaunay.delaunay(points[:,0], points[:,1])
return edges
points = numpy.array([[500000.25, 6220000.25],[500000.5, 6220000.5],[500001.0, 6220001.0],[500002.0, 6220003.0],[500003.0, 6220005.0]])
edges1 = delaunay_edges(points)
edges2 = delaunay_edges_matplotlib(points)
numpy.unique(edges1).shape # Some points missing, presumably nearby ones
numpy.unique(edges2).shape # Includes all points
Run Code Online (Sandbox Code Playgroud) import numpy
a = numpy.array([20090913, 20101020, 20110125])
Run Code Online (Sandbox Code Playgroud)
你能解释一下为什么numpy.datetime64(a.astype("S8").tolist())转换正确但不转换吗numpy.datetime64(a.astype("S8"))?为什么 numpy 函数不接受 numpy 字符串而只接受常规 python 字符串?我正在使用 Numpy 1.6.1 和 Python 2.7.2 Windows 7。
在Windows XP,Python 2.6.6上使用os.path获得意外结果:
a = "D:\temp\temp.txt"
os.path.dirname(a)
>>> 'D:' # Would expect 'D:\temp'
os.path.normpath(a)
>>> 'D:\temp\test.txt'
os.path.basename(a)
>>> '\temp\test.txt' #Would expect 'test.txt'
a.replace("\\", "/")
>>>'D:\temp\test.txt' # Would expect 'D:/temp/test.txt'
Run Code Online (Sandbox Code Playgroud)
有人可以解释发生了什么吗?我怎样才能获得正确/预期的行为?为什么我不能用前斜线替换反斜杠?
编辑:我从wxPython应用程序中的文本字段获取此路径,因此它是一个带有未转义的反斜杠的字符串,我似乎无法用"替换"替换它们.
有没有办法将表的第一列转换为标题?例如,给定此表使用以下脚本获得:
test <- as.matrix(read.csv(file="fileName.csv", sep=",", head=FALSE))
[1,] 72 6467280
[2,] 71 1066945
[3,] 143 1128764
[4,] 69 420286
[5,] 141 137259
[6,] 144 2845182
[7,] 142 151408
[8,] 61 19805
[9,] 52 7520
[10,] 124 3983
Run Code Online (Sandbox Code Playgroud)
我想获得一个表格,其中第一列是标签,并且能够根据这些值重新排列表格.所以我会得到这样的东西.
[52,] 7520
[61,] 19805
[69,] 420286
[71,] 1066945
[72,] 6467280
[124,] 3983
[141,] 137259
[142,] 151408
[143,] 1128764
[144,] 2845182
Run Code Online (Sandbox Code Playgroud)
谢谢