查看张量的形状及阶的个数
import tensorflow as tf
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
tf.compat.v1.disable_eager_execution()
s0 = 1
s1 = [1,2,3]
s2 = [[1,2,3],[4,5,6],[7,8,9]]
s3 = [[[1,2,3]],[[4,5,6]],[[7,8,9]]]
b = tf.constant(s0)
shape1 = tf.shape(b)
rank1 = tf.rank(b)
session = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))
print('张量的值:')
print(session.run(b))
print('张量的形状:')
print(session.run(shape1))
print('张量的阶数:')
print(session.run(rank1))
设计一个感知器来实现逻辑与(and)的运算