TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Study Plan
Evaluate a Scalar Neuron
Neural Networks
Easy

Evaluate one scalar tanh neuron using the supplied input vector, aligned weights, and scalar bias.

a=∑i=1nwixi+ba = \sum_{i=1}^{n} w_i x_i + ba=i=1∑n​wi​xi​+b y=tanh⁡(a)y = \tanh(a)y=tanh(a)

Here n is the vector length, x is inputs, w is weights, i indexes their entries, b is bias, a is the preactivation, and y is the neuron output. For empty input and weight vectors, a equals b.

Return a tuple of two zero-dimensional PyTorch tensors: a first, then y. Both must preserve the inputs’ floating-point dtype and device.

Loading visualization...

Examples

Input: inputs = [2, 0], weights = [-3, 1], bias = 6.881373587

Output: (0.881374, 0.707107)

Explanation: The weighted inputs sum to -6; adding the bias gives the preactivation.

Input: inputs = [1.5], weights = [2], bias = -0.5

Output: (2.5, 0.986614)

Input: inputs = [], weights = [], bias = 0.75

Output: (0.75, 0.635149)

Hint 1

torch.sum reduces a vector to a scalar tensor, including an empty vector.

Hint 2

torch.tanh accepts a zero-dimensional tensor.

Requirements

  • Use PyTorch with the supplied weights and bias.
  • Preserve the supplied float16, float32, or float64 dtype; examples use float64.
  • Do not modify inputs, weights, or bias.

Constraints

  • inputs and weights are finite one-dimensional tensors of equal length, which may be zero.
  • bias is a finite zero-dimensional tensor.
  • All tensors share float16, float32, or float64 dtype and the same device; vectors may be noncontiguous.
Try Similar Problems
Backpropagate Through a Scalar NeuronMediumGradient-Check a Scalar NeuronMediumCreate a Multiplication Value NodeEasyCreate an Addition Value NodeEasyDifferentiate a Tanh ActivationEasyEvaluate a Dense LayerMediumBuild a Scalar Neuron ModuleMediumTopologically Sort a Computation DAGMediumActivation FunctionsEasyDouble DQN TargetEasyPerceptronEasyBatch NormalizationEasy

Accepts: array

Accepts: array

Accepts: number

You must run your code first.

Evaluate a Scalar Neuron

Neural Networks
Easy

Evaluate one scalar tanh neuron using the supplied input vector, aligned weights, and scalar bias.

a=∑i=1nwixi+ba = \sum_{i=1}^{n} w_i x_i + ba=i=1∑n​wi​xi​+b y=tanh⁡(a)y = \tanh(a)y=tanh(a)

Here n is the vector length, x is inputs, w is weights, i indexes their entries, b is bias, a is the preactivation, and y is the neuron output. For empty input and weight vectors, a equals b.

Return a tuple of two zero-dimensional PyTorch tensors: a first, then y. Both must preserve the inputs’ floating-point dtype and device.

Loading visualization...

Examples

Input: inputs = [2, 0], weights = [-3, 1], bias = 6.881373587

Output: (0.881374, 0.707107)

Explanation: The weighted inputs sum to -6; adding the bias gives the preactivation.

Input: inputs = [1.5], weights = [2], bias = -0.5

Output: (2.5, 0.986614)

Input: inputs = [], weights = [], bias = 0.75

Output: (0.75, 0.635149)

Hint 1

torch.sum reduces a vector to a scalar tensor, including an empty vector.

Hint 2

torch.tanh accepts a zero-dimensional tensor.

Requirements

  • Use PyTorch with the supplied weights and bias.
  • Preserve the supplied float16, float32, or float64 dtype; examples use float64.
  • Do not modify inputs, weights, or bias.

Constraints

  • inputs and weights are finite one-dimensional tensors of equal length, which may be zero.
  • bias is a finite zero-dimensional tensor.
  • All tensors share float16, float32, or float64 dtype and the same device; vectors may be noncontiguous.
Try Similar Problems
Backpropagate Through a Scalar NeuronMediumGradient-Check a Scalar NeuronMediumCreate a Multiplication Value NodeEasyCreate an Addition Value NodeEasyDifferentiate a Tanh ActivationEasyEvaluate a Dense LayerMediumBuild a Scalar Neuron ModuleMediumTopologically Sort a Computation DAGMediumActivation FunctionsEasyDouble DQN TargetEasyPerceptronEasyBatch NormalizationEasy

Accepts: array

Accepts: array

Accepts: number

You must run your code first.