小编joh*_*dir的帖子

如何在Python中有效地比较两个无序列表(不是集合)?

a = [1, 2, 3, 1, 2, 3]
b = [3, 2, 1, 3, 2, 1]
Run Code Online (Sandbox Code Playgroud)

a&b应该被认为是相同的,因为它们具有完全相同的元素,只是顺序不同.

问题是,我的实际列表将包含对象(我的类实例),而不是整数.

python algorithm comparison list

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

如何将数组传递给bash函数

如何将数组传递给函数,为什么这不起作用?其他问题的解决方案对我不起作用.为了记录,我不需要复制数组,所以我不介意传递引用.我想做的就是循环它.

$ ar=(a b c)
$ function test() { echo ${1[@]}; }
$ echo ${ar[@]}
a b c
$ test $ar
bash: ${1[@]}: bad substitution
$ test ${ar[@]}
bash: ${1[@]}: bad substitution
Run Code Online (Sandbox Code Playgroud)

arrays bash shell

12
推荐指数
2
解决办法
8025
查看次数

如何将函数应用于numpy数组中的每个第3轴元素?

如果我有一个像这样的numpy数组:

[[[137 153 135]
  [138 154 136]
  [138 153 138]
  ..., 
  [134 159 153]
  [136 159 153]
  [135 158 152]]
  ...,
  [ 57  44  34]
  [ 55  47  37]
  [ 55  47  37]]]
Run Code Online (Sandbox Code Playgroud)

如何对每个[000 000 000]条目应用一个函数,对其进行修改?

# a = numpy array
for x in a:
    for y in x:
        y = modify(y)
Run Code Online (Sandbox Code Playgroud)

我想要实现的是修改转换为numpy数组的PIL图像中的每个(r,g,b)像素.

python numpy python-imaging-library

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