计算数组中的连续相等值 [英] Count consecutive equal values in array

查看:90
本文介绍了计算数组中的连续相等值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有以下numpy数组:

a = np.array([1,5,5,2,3,6,5,2,5,5,5])

我正在尝试提出一个numpy解决方案,以计算给定值连续出现的次数.因此,例如,对于编号5,我想获得:

I'm trying to come up with a numpy solution to count the amount of times a given value appears consecutively. So, for example for number 5 I'd like to get:

array([2,1,3])

它在数组中连续出现3次,每次都有指定的重复次数.

As it appears consecutively 3 times in the array, with the specified amount of repetitions on each time.

推荐答案

以下是根据 查看全文

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