lschoe / mpyc

MPyC: Multiparty Computation in Python
MIT License
367 stars 76 forks source link

How to use the class SecureArray? #80

Closed 1191000814 closed 8 months ago

1191000814 commented 8 months ago

How to use the class SecureArray? It is not seem in the document? I want to transfer a np.ndarray type to secure type, how can I do that?

lschoe commented 8 months ago

It's best to look at a demo like demos/np_id3gini.py to see how to work with secure arrays. Also see the other demos listed in demos/np-run-all.sh

For a basic secure type like secint = mpc.SecInt() you can use b = secint.array(a) to convert a Numpy array a into a secret-shared version b, and then work with b using Numpy operations.

1191000814 commented 8 months ago

Thanks! I have another problem, the SecInt type is unhashable, but I want to use it as the key of a dict, How can I do?

It's best to look at a demo like demos/np_id3gini.py to see how to work with secure arrays. Also see the other demos listed in demos/np-run-all.sh

For a basic secure type like secint = mpc.SecInt() you can use b = secint.array(a) to convert a Numpy array a into a secret-shared version b, and then work with b using Numpy operations.