Is there a NumPy library for a set of calculations?

For fast numerical calculations, I often use NumPy. Although NumPy is a great tool, it is (obviously) not a good choice for given operations, since NumPy works with arrays. Even Python built-in objects are much faster than using NumPy for jobs:


Cooking:

# NumPy arrays a = np.unique(np.random.randint(0, high=1000, size=1000)) b = np.unique(np.random.randint(0, high=1000, size=1000)) # Python built-in set objects sa = set(a) sb = set(b) 

Set Intersection :

 # NumPy timeit.timeit("np.intersect1d(a, b)", setup="from __main__ import a, b, np", number=10000) > 1.3161415259819478 # Python timeit.timeit("sa.intersection(sb)", setup="from __main__ import sa, sb", number=10000) > 0.2791759959945921 

Set the difference :

 # NumPy timeit.timeit("np.setdiff1d(a, b)", setup="from __main__ import a, b, np", number=10000) > 0.6135410660062917 # Python timeit.timeit("sa - sb", setup="from __main__ import sa, sb", number=10000) > 0.21169587498297915 

Establish a connection :

 # NumPy timeit.timeit("np.union1d(a, b)", setup="from __main__ import a, b, np", number=10000) > 0.4114252869854681 # Python timeit.timeit("sa.union(sb)", setup="from __main__ import sa, sb", number=10000) > 0.2402713909978047 

Of course, this is pretty unrepresentative, because a and b contain random integers ... but I tested it several times, also with ranges. NumPy has always been something like 1.5-6x slower than Python's built-in objects.

Also, I think NumPy arrays are not very good when items need to be added or removed often.


Problem . I currently work with sets that usually contain more than 10,000 elements, sometimes even millions of elements. In addition, I add or remove items quite often.

Question: Is there any library for quick installation operations in Python? Some library that offers an API for compiled material for given operations, like NumPy, for arrays / numerical operations?

+7
performance python set numpy
source share

No one has answered this question yet.

See related questions:

2847
Improve SQLite performance per second per second?
873
Big data workflows using pandas
327
Convert to list without creating a new list
43
numpy float: 10x slower than built in arithmetic operations?
27
How to convert python set to numpy array?
8
Are elementary operations faster with NumPy functions than operators?
2
How to vectorize 3D numpy arrays
2
Does Cython offer any reasonably simple and efficient way to iterate over Numpy arrays as if they were flat?
0
default random sampling
-3
Does python timeit calculate installation in count

All Articles