小编MiB*_*der的帖子

如何使用仅包含数据但没有文件名的python解压缩xz文件?

我有一个文件,我可以使用以下命令在linux下解压缩:

unxz < file.xz > file.txt
Run Code Online (Sandbox Code Playgroud)

我怎么能用python做同样的事情?如果我使用python3和tarfile模块并执行以下操作:

import sys
import tarfile
try:
    with tarfile.open('temp.xz', 'r:xz') as t:
        t.extract()
except Exception as e:
    print("Error:", e.strerror)
Run Code Online (Sandbox Code Playgroud)

我得到了异常:ReadError('invalid header').显然,它需要一些xz文件中不存在的文件或目录信息.

那么如何在没有头信息的情况下解压缩文件呢?

python compression tarfile xz

8
推荐指数
1
解决办法
7944
查看次数

使用MATLAB查找坐标列表中每个坐标的第一个和最后一个索引

我有一个坐标列表(x,y),我需要找到列表中每个坐标的第一个和最后一个出现的索引.示例(在我的use-cast中我有~30M坐标):

x = [1 3 7 1 3];
y = [5 1 6 5 1];
first = [1 2 3 1 2];
last  = [4 5 3 4 5];
Run Code Online (Sandbox Code Playgroud)

我使用Matrix和循环实现它,它看起来像这样,但它很慢:

x1 = min(x);
y1 = min(y);
x2 = max(x);
y2 = max(y);
tic
Mlast = zeros(y2-y1+1, x2-x1+1);
Mfirst = Mlast;

ind = sub2ind(size(Mlast),y-y1+1, x-x1+1);

for i1=1:length(ind)
    first = Mfirst(ind(i1));

    if first == 0
        first = i1;
    end

    Mlast(ind(i1)) = i1;
    Mfirst(ind(i1)) = first;
end
Run Code Online (Sandbox Code Playgroud)

我试图将整个过程矢量化,但我只能使用Mlast成功:

ind = sub2ind(size(Mlast),y-y1+1, x-x1+1);
t …
Run Code Online (Sandbox Code Playgroud)

arrays matlab unique

4
推荐指数
1
解决办法
53
查看次数

标签 统计

arrays ×1

compression ×1

matlab ×1

python ×1

tarfile ×1

unique ×1

xz ×1