代码用法链接

keras用法

models.
搭建模型 ------ 配置训练方法 ------ 执行训练过程 ------ 统计参数数目
Sequential()         compile().                 fit()                         summary()


tf 的 shape
在这里插入图片描述

aaa = tf.random_uniform([2,3],minval=-0.1,maxval = 0.1)
print(aaa.shape)      # --- 1

with tf.Session() as sess:
    print(aaa.get_shape())     # --- 2

输出:
(2, 3)      # --- 1
(2, 3)      # --- 2

numpy 的shape:
在这里插入图片描述


nn.embedding()


tf.placeholder()

a=tf.placeholder(tf.int32, shape=[2,2])

with tf.Session() as sess:
     print(sess.run(a,feed_dict={a:[[2,4],[3,3]]}))
 
输出:
[[2 4]
 [3 3]]
  
bb = tf.placeholder(tf.int32, shape=[2, ])
cc = tf.placeholder(tf.int32, shape=[2])
with tf.Session() as sess:
    print(sess.run(b, feed_dict={b: [2,2]  }))
    print(sess.run(c, feed_dict={c: [2, 2] }))

输出:
bb =  [2 2]
cc =  [2 2]

b = tf.placeholder(tf.int32, shape=[None, None])
c = tf.placeholder(tf.int32, shape=[2,])
d = tf.placeholder(tf.float32, shape=[None,1])
e = tf.placeholder(tf.float32, shape=[1, None])

print(b.shape)   # (?, ?)
print(c.shape)   # (2,)
print(d.shape)   # (?, 1)
print(e.shape)   # (1, ?)


with tf.Session() as sess:
    print(sess.run(b,feed_dict={b:[[4,4,2],[3,5,6],[5,6,7]]}))
    print(sess.run(c,feed_dict={c:[42,33] }))
    print(sess.run(d,feed_dict={d:[[42],[4],[6]] }))
    print(sess.run(e, feed_dict={e:[[42,4,5,6]] }))

输出:
b = [[4 4 2]
     [3 5 6]
     [5 6 7]]
c = [42 33]
d = [[42.]
     [ 4.]
     [ 6.]]
e = [[42.  4.  5.  6.]]


矩阵None的用法:对应维度加一维
在 ndarray 和 tensor 类型使用,list 不适用(会报错)

b=np.array([[3,4,5,6],[7,8,9,10],[11,2,3,33]])
print(b)                  # --- 1        
print(b[:,])              # --- 1          
print(b[:,None])          # --- 2              

print(b.shape)                # (3, 4)
print(b[:,None].shape)        # (3, 1, 4)
print(b[None,:].shape)        # (1, 3, 4)    

输出:
# b 和 b[:,]        # --- 1
[[ 3  4  5  6]
 [ 7  8  9 10]
 [11  2  3 33]]
 
# b[:,None]         # --- 2
[[[ 3  4  5  6]]

 [[ 7  8  9 10]]

 [[11  2  3 33]]]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值