如何删除矩阵中的某些条目.我正在从Matlab转换为python [英] How can I remove some entries in a matrix. I am converting from matlab to python

查看:97
本文介绍了如何删除矩阵中的某些条目.我正在从Matlab转换为python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要转换的matlab代码

Here is a matlab code i would like to convert

m=100;
n=100      
idx_MV = randperm(m*n);
Q = ones(n, m);
Q(idx_MV(1:round(MV*m*n))) = 0;

我可以得到这段代码的python等效代码吗?谢谢

can i get a python equivalent of this piece of code? thanks

推荐答案

我知道了.谢谢@Ludovic

I figured it out. Thanks @Ludovic

m=100
n=100
MV=0.4
idx = np.random.permutation(m*n)
idx2 = idx[1:round(MV*m*n)]
Q.reshape(-1, 1)[idx2] = 0

这篇关于如何删除矩阵中的某些条目.我正在从Matlab转换为python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆