我如何在numpy中复制此matlab函数? [英] How do i replicate this matlab function in numpy?
本文介绍了我如何在numpy中复制此matlab函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[A,I] = histc([0.9828 0.4662 0.5245 0.9334 0.2163],[0.0191 0.2057 0.2820 0.2851 1.0000])
这是带有结果的 MATLAB 代码:
That is the MATLAB code with the results:
A =
0 1 0 4 0
I =
4 4 4 4 2
我需要的是我.我尝试使用np.histogram,但这给了我:
What I need is I. I've tried using np.histogram but it gives me this:
>>> a,b = np.histogram([0.9828 , 0.4662 , 0.5245 , 0.9334 , 0.2163],[0.0191 , 0.2057 , 0.2820 , 0.2851 , 1.0000])
>>> a
array([0, 1, 0, 4])
>>> b
array([ 0.0191, 0.2057, 0.282 , 0.2851, 1. ])
我想获取我的数组/矩阵中每个元素进入的容器.
I want to get the bins that each element in my array/matrix goes into.
推荐答案
您正在寻找的是 numpy.digitize
:
返回输入数组中每个值所属的bin的索引.
Return the indices of the bins to which each value in input array belongs.
>>> a = np.digitize([0.9828 , 0.4662 , 0.5245 , 0.9334 , 0.2163],[0.0191 , 0.2057 , 0.2820 , 0.2851 , 1.0000])
>>> print(a)
[4 4 4 4 2]
这篇关于我如何在numpy中复制此matlab函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文