python,numpy中一些与矩阵变化相关的问题

1、保留两个矩阵中对应位置较大(较小)的值

import numpy as np
arr1 = np.random.randint(1,10,[3,3])
arr2 = np.random.randint(1,10,[3,3])
arr = arr1 * (arr1 > arr2) + arr2 * (arr2 > arr1)

2、单独选择一个通道,同时保持维度不变

import torch
inputs = torch.randn([2,3,224,224])
# 选择一个通道,维度减1
inputs1 = inputs[:,0,:,:] # shape(2,224,224)
# 选择一个通道,维度不变
inputs1 = inputs[:,0:1,:,:] # shape(2,1,224,224)

猜你喜欢

转载自blog.csdn.net/Huang_Fj/article/details/121982124