Kev1n91
Kev1n91

Reputation: 3693

How to get PI in tensorflow?

I could not find any information about mathemtical constants in the Tensorflow API

neither in Basic Math functions nor in Math Ops.

I was able to get it by

import math as m
pi = tf.constant(m.pi)

However, this would mean to include another library, - so I wonder if there is this functionallity for mathemtical constants like pi, or euler already provided inside tensorflow?

Upvotes: 15

Views: 27739

Answers (3)

qmzp
qmzp

Reputation: 89

Tensorflow already has pi and e in tensorflow.experimental.numpy

>>> import tensorflow as tf
>>> from tensorflow.experimental import numpy as tnp # start using tnp instead of numpy or math library
>>> tnp.pi, tnp.e
3.141592653589793, 2.718281828459045

Upvotes: 2

ChaosPredictor
ChaosPredictor

Reputation: 4071

As I know NO, and there's a reason for it. If each library define it own pi will be lots of code duplications! You did it right

Upvotes: 6

AKX
AKX

Reputation: 169338

math is in the Python standard library, not a third-party module.

I don't see why using it is a problem whatsoever.

Upvotes: 19

Related Questions