TensorFlow2.1入门笔记2

预备知识tf.where(条件语句,真返回A,假返回B)np.random.RandomState.rand(维度):返回一个[0,1)之间的随机数np.vastack(数组1,数组2):将两个数组垂直方向叠加import tensorflow as tfa = tf.constant([1, 2, 3, 1, 1])b = tf.constant([0, 1, 3, 4, 5])c = tf.where(tf.greater(a, b), a, b) # 若a>b,返回a对应位置的
摘要由CSDN通过智能技术生成

tf.where(条件语句,真返回A,假返回B)
np.random.RandomState.rand(维度):返回一个[0,1)之间的随机数
np.vastack(数组1,数组2):将两个数组垂直方向叠加

import tensorflow as tf

a = tf.constant([1, 2, 3, 1, 1])
b = tf.constant([0, 1, 3, 4, 5])
c = tf.where(tf.greater(a, b), a, b)  # 若a>b,返回a对应位置的元素,否则返回b对应位置的元素
print("c:", c)

# c: tf.Tensor([1 2 3 4 5], shape=(5,), dtype=int32)

import numpy as np

rdm = np.random.RandomState(seed=1)
a = rdm.rand()
b = rdm.rand(2, 3)
print("a:", a)
print("b:", b)

# a: 0.417022004702574
# b: [[7.20324493e-01 1.14374817e-04 3.02332573e-01]
#  [1.46755891e-01 9.23385948e-02 1.86260211e-01]]

import numpy as np

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.vstack((a, b))
print("c:\n", c)

# c:
#  [[1 2 3]
#  [4 5 6]]

np.mgridp[] .ravel() np.c_[]:生成网格坐标点
np.magrid[起始值:结束值:步长,起始值:结束值:步长](多组数据用逗号隔开,起始值闭区间,终止值开区间)
x.ravel():将x变为一维数组
np.c_[数组1,数组2,…]:讲返回的间隔数值点配对输出

import numpy as np
import tensorflow as tf

# 生成等间隔数值点
x, y = np.mgrid[1:3:1, 2:4:0.5]
# 将x, y拉直,并合并配对为二维张量,生成二维坐标点
grid = np.c_[x.ravel(), y.ravel()]
print("x:\n", x)
print("y:\n", y)
print("x.ravel():\n", x.ravel())
print("y.ravel():\n", y.ravel())
print('grid:\n', grid)

# x:
#  [[1. 1. 1. 1.]
#  [2. 2. 2. 2.]]
# y:
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值