Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between numpy ediff1d and diff

Tags:

python

numpy

I have recently discovered numpy.ediff1d Is there an advantage of using numpy.ediff1d instead of numpy.diff or what is it's usecase?

like image 654
P3trus Avatar asked Aug 18 '16 09:08

P3trus


1 Answers

Prior to numpy 1.16.0, one could use ediff1d(ar, to_end, to_begin) to pad the result of ar[1:] - ar[-1:]. But from 1.16.0 diff() supports padding and covers all of ediff1d() functionality and much more. Also, diff() has same performance in most cases and outperforms ediff1d() for boolean arrays.

like image 140
Виктор Дремов Avatar answered Oct 05 '22 11:10

Виктор Дремов