import numpy as np
import tensorflow as tf tf.convert_to_tensor(np.ones([2, 3]))
tf.convert_to_tensor(np.zeros([2, 3]))
list
tf.convert_to_tensor([1, 2])
tf.convert_to_tensor([1, 2.])
tf.convert_to_tensor([[1], [2.]])
zeros
tf.zeros([])
tf.zeros([1])
tf.zeros([2, 2])
tf.zeros([2, 3, 3])
a = tf.constant([0])
tf.zeros_like(a) # 等同于tf.zeros(a.shape)
ones
tf.ones(1)
tf.ones([])
tf.ones([2])
tf.ones([2, 3]) a = tf.constant([0])
tf.ones_like(a) # # 等同于tf.ones(a.shape)
fill
tf.fill([2, 2], 0)
tf.fill([2, 2], 0)
tf.fill([2, 2], 1)
tf.fill([2, 2], 9)
random
# 正态分布,均值为1,方差为1
tf.random.normal([2, 2], mean=1, stddev=1) tf.random.normal([2, 2]) # 截断的正态分布,
tf.random.truncated_normal([2, 2], mean=0, stddev=1) # 均匀分布
tf.random.uniform([2, 2], minval=0, maxval=1) tf.random.uniform([2, 2], minval=0, maxval=100, dtype=tf.int32)
打乱idx后,a和b的索引不变

idx = tf.range(10)
idx = tf.random.shuffle(idx)
idx a = tf.random.normal([10, 784])
b = tf.random.uniform([10], maxval=10, dtype=tf.int32)
b a = tf.gather(a, idx)
b = tf.gather(b, idx)
b
constant

tf.constant(1)
tf.constant([1])
tf.constant([1, 2.])
tf.constant([[1, 2], [3., 2]])
loss计算
无bias的loss
out = tf.random.uniform([4, 10])
out y = tf.range(4)
y = tf.one_hot(y, depth=10)
y loss = tf.keras.losses.mse(y, out)
loss loss = tf.reduce_mean(loss)
loss

吴裕雄--天生自然TensorFlow2教程:创建Tensor的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型

    list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...

  2. 吴裕雄--天生自然TensorFlow2教程:测试(张量)- 实战

    import tensorflow as tf from tensorflow import keras from tensorflow.keras import datasets import os ...

  3. 吴裕雄--天生自然TensorFlow2教程:合并与分割

    import tensorflow as tf # 6个班级的学生分数情况 a = tf.ones([4, 35, 8]) b = tf.ones([2, 35, 8]) c = tf.concat( ...

  4. 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战

    import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...

  5. 吴裕雄--天生自然TensorFlow2教程:函数优化实战

    import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...

  6. 吴裕雄--天生自然TensorFlow2教程:反向传播算法

  7. 吴裕雄--天生自然TensorFlow2教程:链式法则

    import tensorflow as tf x = tf.constant(1.) w1 = tf.constant(2.) b1 = tf.constant(1.) w2 = tf.consta ...

  8. 吴裕雄--天生自然TensorFlow2教程:多输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([2, 4]) w = tf.random.normal([4, 3]) b = tf.zeros([3]) ...

  9. 吴裕雄--天生自然TensorFlow2教程:单输出感知机及其梯度

    import tensorflow as tf x = tf.random.normal([1, 3]) w = tf.ones([3, 1]) b = tf.ones([1]) y = tf.con ...

随机推荐

  1. vue学习(四)插槽

    一 匿名插槽 // 语法 Vue.component('MBtn', { template: ` <button> <slot></slot> </butto ...

  2. yum 安装 Mysql error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 开启远程连接 修改登入密码 忘记root密码 配置防火墙规则 随手mark

    yum 安装 MYsql:        yum install mysql mysql-server mysql-devel -y 1.1 登入报错: ERROR 1045 (28000): Acc ...

  3. UVA - 12113 Overlapping Squares(重叠的正方形)

    题意:给定一个4*4的棋盘和棋盘上所呈现出来的纸张边缘,问用不超过6张2*2的纸能否摆出指定的形状. 分析:2*2的纸在4*4的棋盘上总共有9种放置位置,枚举所有的放置位置即可.枚举情况总共种. #p ...

  4. HDU 5280 BestCoder Round #47 1001:Senior's Array

    Senior's Array  Accepts: 199  Submissions: 944  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit ...

  5. 洛谷 P5146 最大差值

    题目传送门 好水的题... AC代码: #include<iostream> #include<cstdio> using namespace std; ,a,ans = -; ...

  6. B站 React教程笔记day1(4)调色板案例

    视频地址 main.js import React from "react" import { render } from "react-dom" import ...

  7. leetcode - 两数之和Ⅳ 输入BST(653)

    题目描述:给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. 解题思路:根据二叉搜索树的特点,对二叉搜索树进行中序遍历可以得到一个从小到达排 ...

  8. 一小时搞定Eureka

    一.什么是Eureka Eureka是Netflix公司开源的产品,它是一种基于REST( Representational State Transfer )的服务,主要用于AWS云. Eureka提 ...

  9. 吴裕雄--天生自然 JAVASCRIPT开发学习:switch 语句

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. LeetCode刷题笔记(1-9)

    LeetCode1-9 本文更多是作为一个习题笔记,没有太多讲解 1.两数之和 题目请点击链接 ↑ 最先想到暴力解法,直接双循环,但是这样复杂度为n平方 public int[] twoSum(int ...