shape.gradient使用示例

android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"        //滚动条背景

    Android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"    //滚动条




scrollbar_vertical_track.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#3333FF" android:endColor="#8080FF"
            android:angle="0"/>
    <corners android:radius="6dp" />
</shape>

 

scrollbar_vertical_thumb.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#505050" android:endColor="#C0C0C0"
            android:angle="0"/>
    <corners android:radius="0dp" />
</shape>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`tape.gradient(target, sources)`是TensorFlow中的一个函数,其中`target`是一个标量,而`sources`是一个张量或者张量列表。 这个函数的作用是计算`target`相对于`sources`的梯度。举个例子,如果我们有一个函数`y = f(x)`,其中`x`是一个张量,`y`是一个标量,我们可以使用`tape.gradient(y, x)`来计算`y`相对于`x`的梯度。 该函数使用了TensorFlow的自动微分机制,它会自动构建一个计算图,并在计算图中记录所有的操作,然后使用链式法则计算出梯度。在使用前,需要先通过`tf.GradientTape()`创建一个上下文环境,在这个上下文中记录所有的操作。 下面是一个使用`tape.gradient`函数的简单示例: ```python import tensorflow as tf x = tf.constant([1.0, 2.0, 3.0]) with tf.GradientTape() as tape: tape.watch(x) y = x * x + 2 * x + 1 # y = x^2 + 2x + 1 dy_dx = tape.gradient(y, x) print(dy_dx) # 输出: tf.Tensor([4. 6. 8.], shape=(3,), dtype=float32) ``` 在上面的示例中,我们定义了一个张量`x`,然后使用`tf.GradientTape()`创建了一个上下文环境,在这个上下文中,我们定义了一个标量`y`,然后使用`tape.gradient(y, x)`计算了`y`相对于`x`的梯度。 需要注意的是,对于某些张量,我们需要在使用`tape.gradient`函数前使用`tape.watch`方法告诉TensorFlow需要对它进行梯度计算。在上面的示例中,我们对`x`使用了`tape.watch(x)`。 另外,需要注意的是,`tape.gradient`函数只能计算标量相对于张量的梯度,如果我们需要计算张量相对于张量的梯度,可以先对每个标量分别计算梯度,然后再将它们组合起来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值