实现购买2个苹果
登录后复制
apple = 100apple_num = 2tax = 1.1apple_price = mul_apple_layer.forward(apple, apple_num)price = mul_tax_layer.forward(apple_price, tax)dprice = 1dapple_price, dtax = mul_tax_layer.backward(dprice)dapple, dapple_num = mul_apple_layer.backward(dapple_price)print('仅使用乘法层:购买2个苹果和消费税的例子')print("price:", int(price))print("dApple:", dapple)print("dApple_num:", int(dapple_num))print("dTax:", dtax)1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.
实现购买2个苹果和3个橘子的例子
登录后复制
apple = 100apple_num = 2orange = 150orange_num = 3tax = 1.1apple_price = mul_apple_layer.forward(apple, apple_num) # (1)orange_price = mul_orange_layer.forward(orange, orange_num) # (2)all_price = add_apple_orange_layer.forward(apple_price, orange_price) # (3)price = mul_tax_layer.forward(all_price, tax) # (4)dprice = 1dall_price, dtax = mul_tax_layer.backward(dprice) # (4)dapple_price, dorange_price = add_apple_orange_layer.backward(dall_price) # (3)dorange, dorange_num = mul_orange_layer.backward(dorange_price) # (2)dapple, dapple_num = mul_apple_layer.backward(dapple_price) # (1)print('混合使用加法层和乘法层,实现购买2个苹果和3个橘子的例子')print("price:", int(price))print("dApple:", dapple)print("dApple_num:", int(dapple_num))print("dOrange:", dorange)print("dOrange_num:", int(dorange_num))print("dTax:", dtax)1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删