小编NPB*_*NPB的帖子

使用sed将带有斜杠的已定义变量的空格替换为空格

我试图用sed替换带有定义变量的空格的行.

例如,

我想用$ lan替换'a dumb string',并且lan ="〜/ afile.py

我认为这条线是

sed "s/a dumb string/$lan/g" file.txt
Run Code Online (Sandbox Code Playgroud)

但是这会在file.txt中将'哑字符串'部分留空.

我的问题似乎很简单.任何帮助深表感谢.

unix bash sed

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

numpy /:冒号等效的数组赋值

我试图将两个不同大小的数组的python/numpy索引联系起来,但我不能通过子程序将索引一从小数组传递到大数组.

例如,我有两个numpy数组:a1a2.a1.shape = (240,33,258)a2.shape = (240,40,33,258).我在a1中找到索引并将这些索引与之相关联a2.即.,index1 = numpy.where(a > n).我可以抓住我感兴趣的数据

dat1 = a1[index]
dat2 = a2[index[0],:,index[1],index[2]]
Run Code Online (Sandbox Code Playgroud)

结果数据形状为dat1.shape = (n)dat2.shape = (n, 40).为了加速程序,我想通过一个子程序传递索引,但我不能通过[index[0],:,index[1],index[2]]一个子程序,因为我不能传递冒号':'.

我相信我的解决方案是在子程序中将等效数字传递给':',但我还没有找到答案.

有帮助吗?

非常感谢你

python indexing numpy

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

标签 统计

bash ×1

indexing ×1

numpy ×1

python ×1

sed ×1

unix ×1