小编Aby*_*byy的帖子

如何仅通过列python减去数组?

我有二维数组

 [1, 5],
 [2, 7],
 [3, 9] 
Run Code Online (Sandbox Code Playgroud)

我想结果数组

 [1, 5],
 [2, 2],
 [3, 2] 
Run Code Online (Sandbox Code Playgroud)

这是通过仅减去列并保留行作为其实现的。(7-5) (9-7)

我在下面尝试了这个,但我无法获得正确的输出

import numpy as np

timeline = np.array([[1,5],
                     [2,7],
                     [3,9]]) 

def non_adjacent_diff(row):
    not_zero_index = np.where(row != 0)
    diff = row[not_zero_index][1:] - row[not_zero_index][:-1]
    np.put(row, not_zero_index[0][1:], diff)
    return row

np.apply_along_axis(non_adjacent_diff, 1, timeline)

print(timeline)
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

0
推荐指数
1
解决办法
52
查看次数

更改启动磁盘GCP的源映像

我想更改附加到正在运行的虚拟机实例之一的启动磁盘的源映像。启动磁盘和虚拟机是使用 terraform 创建的。无论如何,我们可以分离启动盘并附加新的启动盘吗?或者还有其他新方法可以做到这一点吗?或者有什么方法可以使用 Terraform 来实现这一点?请协助。

google-cloud-storage google-compute-engine google-cloud-platform terraform-provider-gcp

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