Use same numpy code with numpy and tensorflow numpy emulation

I have code using the numpy API and the same code using the TF2 tensor API. Is there a cookbook somewhere that shows how to use either module with the same file?

I suspect it would be:
class A:
def use_numpy:
return self.np.mean([1,2,3])

class NP(A):
def init:
use python module package to load the numpy module for this object

class TF2(A):
def init:
use python module package to load the tensorflow.experimental module for this object

Is there an example somewhere in the TF documentation that shows how to do this? It would be very helpful for those of us trying to maintain simple codebases. Otherwise we have to have two versions of the same code, and two versions of the same unit tests.

Hi @Lance_N ,

There is no NumPy to vanilla TF guide but check out the tf.experimenal.numpy API reference and the TF NumPy guide for a similiar interface.

1 Like