Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tạo tensor và hiển thị thông điệp với TensorFlow (Hello World)


TensorFlow (Google) framework học máy mã nguồn mở, tối ưu NumPy/tensor, scalable, GPU, tài liệu tốt.

Cài đặt: pip install tensorflow

Tensor: mảng đa chiều với Rank, Type, Shape.

Tìm hiểu "Hello World" của TensorFlow.

Sử dụng Jupyter Notebook: pip install tensorflow.

Tạo tensor và hiển thị thông điệp với TensorFlow (Hello World)

Ví dụ

import tensorflow as tf

hello = tf.constant("hello there")
print(hello)
print(hello.numpy())

Đầu ra

tf.Tensor(b'hello there', shape=(), dtype=string)
b'hello there'

Giải thích

  • Import TensorFlow, alias tf.
  • Tạo hằng số tensor bằng tf.constant.
  • In tensor object (hiển thị metadata: shape, dtype).
  • Chuyển về NumPy bằng .numpy() để lấy giá trị thô (bytes string).