TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Study Plan
Create a Multiplication Value Node
Neural NetworksCalculus
Easy

Create a scalar multiplication node from the left and right leaf dictionaries, each containing id and data.

z=xyz = xyz=xy

Here x and y are the left and right data values, and z is their product.

Return a new dictionary with exactly id, data, grad, op, and parents: id is output_id, data is z as a Python float, grad is 0.0, op is the string "*", and parents is a list containing the original left and right objects in that order.

Loading visualization...

Examples

Input: left={'id':'a','data':2.0}, right={'id':'b','data':3.0}, output_id='c'

Output: {'id':'c','data':6.0,'grad':0.0,'op':'*','parents':[{'id':'a','data':2.0},{'id':'b','data':3.0}]}

Explanation: The output stores the product and retains the exact two input records as its ordered parents.

Input: left={'id':'x','data':-4.0}, right={'id':'y','data':1.5}, output_id='product'

Output: {'id':'product','data':-6.0,'grad':0.0,'op':'*','parents':[{'id':'x','data':-4.0},{'id':'y','data':1.5}]}

Input: left={'id':'zero','data':0.0}, right={'id':'scale','data':-8.0}, output_id='zero_product'

Output: {'id':'zero_product','data':-0.0,'grad':0.0,'op':'*','parents':[{'id':'zero','data':0.0},{'id':'scale','data':-8.0}]}

Hint 1

Dictionary indexing gives access to each leaf’s data field.

Hint 2

A list stores references to its items without copying the dictionaries.

Requirements

  • Use Python floating-point arithmetic (64-bit); NumPy is available.
  • Retain the original parent objects, not copies or their IDs.
  • Do not modify either input dictionary.

Constraints

  • Leaf IDs and output_id are distinct nonempty strings.
  • Leaf data values are finite numbers and are not Boolean values.
  • The computed product must be finite.
Try Similar Problems
Create an Addition Value NodeEasyTrace a Reachable Expression GraphMediumBuild a Scalar Expression GraphMediumBackpropagate Through a Scalar NeuronMediumTopologically Sort a Computation DAGMediumAccumulate Shared-Path GradientsMediumGradient-Check a Scalar NeuronMediumRun Reverse-Mode AutodiffHardBasic AutogradEasyChain Rule Through a 3-Layer NetworkMediumBackpropagation Through a Computation GraphHardJacobian of a Neural Network LayerHard

Accepts: object

Accepts: object

Accepts: string

You must run your code first.

Create a Multiplication Value Node

Neural NetworksCalculus
Easy

Create a scalar multiplication node from the left and right leaf dictionaries, each containing id and data.

z=xyz = xyz=xy

Here x and y are the left and right data values, and z is their product.

Return a new dictionary with exactly id, data, grad, op, and parents: id is output_id, data is z as a Python float, grad is 0.0, op is the string "*", and parents is a list containing the original left and right objects in that order.

Loading visualization...

Examples

Input: left={'id':'a','data':2.0}, right={'id':'b','data':3.0}, output_id='c'

Output: {'id':'c','data':6.0,'grad':0.0,'op':'*','parents':[{'id':'a','data':2.0},{'id':'b','data':3.0}]}

Explanation: The output stores the product and retains the exact two input records as its ordered parents.

Input: left={'id':'x','data':-4.0}, right={'id':'y','data':1.5}, output_id='product'

Output: {'id':'product','data':-6.0,'grad':0.0,'op':'*','parents':[{'id':'x','data':-4.0},{'id':'y','data':1.5}]}

Input: left={'id':'zero','data':0.0}, right={'id':'scale','data':-8.0}, output_id='zero_product'

Output: {'id':'zero_product','data':-0.0,'grad':0.0,'op':'*','parents':[{'id':'zero','data':0.0},{'id':'scale','data':-8.0}]}

Hint 1

Dictionary indexing gives access to each leaf’s data field.

Hint 2

A list stores references to its items without copying the dictionaries.

Requirements

  • Use Python floating-point arithmetic (64-bit); NumPy is available.
  • Retain the original parent objects, not copies or their IDs.
  • Do not modify either input dictionary.

Constraints

  • Leaf IDs and output_id are distinct nonempty strings.
  • Leaf data values are finite numbers and are not Boolean values.
  • The computed product must be finite.
Try Similar Problems
Create an Addition Value NodeEasyTrace a Reachable Expression GraphMediumBuild a Scalar Expression GraphMediumBackpropagate Through a Scalar NeuronMediumTopologically Sort a Computation DAGMediumAccumulate Shared-Path GradientsMediumGradient-Check a Scalar NeuronMediumRun Reverse-Mode AutodiffHardBasic AutogradEasyChain Rule Through a 3-Layer NetworkMediumBackpropagation Through a Computation GraphHardJacobian of a Neural Network LayerHard

Accepts: object

Accepts: object

Accepts: string

You must run your code first.