-
Notifications
You must be signed in to change notification settings - Fork 0
TesorflowLearning
igheyas edited this page Aug 12, 2025
·
3 revisions
Here’s the exact CMD commands for your setup:
REM 1. Navigate to your target directory
cd C:\Users\IAGhe\OneDrive\Documents\Learning\Python
REM 2. Create a virtual environment (call it 'tf_cpu_env')
python -m venv tf_cpu_env
REM 3. Activate the virtual environment
tf_cpu_env\Scripts\activate
REM 4. Upgrade pip to latest
python -m pip install --upgrade pip
REM 5. Install TensorFlow (CPU) and Jupyter Notebook
pip install tensorflow jupyter ipykernel
REM 6. Make this virtual environment available in Jupyter
python -m ipykernel install --user --name=tf_cpu_env --display-name "Python (tf_cpu_env)"
REM 7. (Optional) Install extra common packages for data science
pip install numpy pandas matplotlib seaborn scikit-learn
REM 8. Launch Jupyter Notebook
jupyter notebook
Inside a notebook:
import tensorflow as tf
print(tf.__version__)
print("Eager execution:", tf.executing_eagerly())
t = tf.constant([[1, 2], [3, 4]], dtype=tf.float32)
print(t)
print("Shape:", t.shape)
print("Dtype:", t.dtype)
t = tf.constant([[1, 2], [3, 4]], dtype=tf.float32)
print(t)
print("Shape:", t.shape)
print("Dtype:", t.dtype)
# Change dtype
t_int = tf.cast(t, dtype=tf.int32)
print(t_int)
# Reshape
t_reshaped = tf.reshape(t, (4, 1))
print(t_reshaped)
a = tf.constant([1, 2, 3], dtype=tf.float32)
b = tf.constant([[1], [2], [3]], dtype=tf.float32)
print(a + b) # Broadcasting
import tensorflow as tf
# Example tensors
x = tf.constant([1.0, 2.0, 3.0], dtype=tf.float32)
y = tf.constant([4.0, 5.0, 6.0], dtype=tf.float32)
print("x:", x.numpy())
print("y:", y.numpy())
# --- Basic arithmetic ---
print("\nAddition:", tf.add(x, y).numpy()) # x + y
print("Subtraction:", tf.subtract(x, y).numpy()) # x - y
print("Multiplication:", tf.multiply(x, y).numpy()) # x * y
print("Division:", tf.divide(x, y).numpy()) # x / y
# --- Reductions ---
print("\nSum of x:", tf.reduce_sum(x).numpy()) # 1.0 + 2.0 + 3.0
print("Mean of y:", tf.reduce_mean(y).numpy()) # average of y
# --- Mathematical functions ---
print("\nExponent (e^x):", tf.math.exp(x).numpy())
print("Natural log:", tf.math.log(y).numpy())
print("Square root:", tf.math.sqrt(y).numpy())
# --- Combining operations ---
z = tf.multiply(x, y) # elementwise product
result = tf.reduce_mean(tf.math.sqrt(z))
print("\nMean of sqrt(x * y):", result.numpy())