如果对python或者tensor感兴趣,欢迎加微信wangqime 作为新手讨论交流也算是一种印象加深 提升的方式
#tensor属性 device:tensor程序所在的设备名称 with tf.device('cpu'): a = tf.constant(123) print(a.device) # a如果在cpu上 转移到gpu上运行的话如下: with tf.device('cpu'): a = tf.constant([[1, 2, 3], [2, 5, 6], [8, 9, 10]]) # a = a.gpu() # print(a.device) # tensor数据类型转换为numpy类型 print(a.numpy()) # 查看tensor数据类型的行列数,形状shape属性 print(a.shape) # 查看tensor数据类型的纬度ndim属性 或者 tf.rank(tensor)方法 print(a.ndim) print(tf.rank(a)) # 举例多维的打印纬度 mytf = tf.ones([4, 5, 3], dtype=tf.int32) print(tf.rank(mytf)) print(mytf) # 是否为tensor数据方法:tf.is_tensor(tensor) 或 isinstance(tensor,tf.Tensor) print(tf.is_tensor(mytf)) print(isinstance(mytf, tf.Tensor)) print('---------') # dtype 属性判断tensor数据类型 print(mytf.dtype)
tensor数据的方法 和 属性有:
# tensor 指某个tf数据,比如 [[1 1 1 1],[1 1 1 1]] tf.device() tensor.cpu() tensor.gpu() tensor.numpy() tf.rank(tensor) tf.ones() tf.is_tensor() isinstance() ------------------- tensor.dtype tensor.shape
网络世界,不加微信QQ手机,留言沟通
发表评论