Python में TensorFlow परिचय
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School
add(), multiply(), matmul(), और reduce_sum()gradient(), reshape(), और random()| ऑपरेशन | उपयोग |
|---|---|
gradient() |
किसी बिंदु पर फंक्शन की ढलान निकालता है |
reshape() |
टेन्सर का आकार बदलता है (जैसे 10x10 से 100x1) |
random() |
प्रायिकता वितरण से सैंपल लेकर टेन्सर भरता है |
कई समस्याओं में हमें किसी फंक्शन का ऑप्टिमम खोजना होता है।
यह gradient() ऑपरेशन से किया जा सकता है।


# Import tensorflow under the alias tf
import tensorflow as tf
# Define x
x = tf.Variable(-1.0)
# Define y within instance of GradientTape
with tf.GradientTape() as tape:
tape.watch(x)
y = tf.multiply(x, x)
# Evaluate the gradient of y at x = -1
g = tape.gradient(y, x)
print(g.numpy())
-2.0

# Import tensorflow as alias tf
import tensorflow as tf
# Generate grayscale image
gray = tf.random.uniform([2, 2], maxval=255, dtype='int32')
# Reshape grayscale image
gray = tf.reshape(gray, [2*2, 1])

# Import tensorflow as alias tf
import tensorflow as tf
# Generate color image
color = tf.random.uniform([2, 2, 3], maxval=255, dtype='int32')
# Reshape color image
color = tf.reshape(color, [2*2, 3])

Python में TensorFlow परिचय