TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement z-Score Standardization

Data Processing
Easy

Standardize numeric data to zero mean and unit population variance along a selected axis:

z=x−μσz = \frac{x - \mu}{\sigma}z=σx−μ​

Here, xxx is an input value, μ\muμ is the mean of its selected slice, σ\sigmaσ is the population standard deviation of that slice, and zzz is the standardized value. Use column-wise slices when axis=0 and row-wise slices when axis=1. If a slice has standard deviation at most eps, return zeros for that slice. Return a NumPy array.

Loading visualization...

Examples

Input: X = [[1, 2], [3, 6], [5, 10]], axis = 0, eps = 1e-8

Output: [[-1.224745, -1.224745], [0.0, 0.0], [1.224745, 1.224745]]

Explanation: Both columns have the same relative spacing, so their standardized values match.

Hint 1

Use np.mean(..., keepdims=True) and np.std(..., keepdims=True) along axis.

Hint 2

Use np.where(std > eps, std, 1.0) before dividing.

Requirements

  • Compute the population mean and standard deviation along the selected axis
  • Preserve dimensions during reductions so values broadcast back to X
  • Map every slice with standard deviation at most eps to zeros
  • Return a NumPy array of floating-point values

Constraints

  • X is a nonempty one-dimensional or two-dimensional numeric list
  • axis is 0 for one-dimensional inputs and either 0 or 1 for two-dimensional inputs
  • eps is positive
  • Use NumPy only
Try Similar Problems
Min Max ScalingRobust ScalingLog TransformRank TransformMatrix Normalization

Sign in to take notes on this problem

Case 1

Accepts: array

Accepts: number

Accepts: number

You must run your code first.
PrevNext

Implement z-Score Standardization

Data Processing
Easy

Standardize numeric data to zero mean and unit population variance along a selected axis:

z=x−μσz = \frac{x - \mu}{\sigma}z=σx−μ​

Here, xxx is an input value, μ\muμ is the mean of its selected slice, σ\sigmaσ is the population standard deviation of that slice, and zzz is the standardized value. Use column-wise slices when axis=0 and row-wise slices when axis=1. If a slice has standard deviation at most eps, return zeros for that slice. Return a NumPy array.

Loading visualization...

Examples

Input: X = [[1, 2], [3, 6], [5, 10]], axis = 0, eps = 1e-8

Output: [[-1.224745, -1.224745], [0.0, 0.0], [1.224745, 1.224745]]

Explanation: Both columns have the same relative spacing, so their standardized values match.

Hint 1

Use np.mean(..., keepdims=True) and np.std(..., keepdims=True) along axis.

Hint 2

Use np.where(std > eps, std, 1.0) before dividing.

Requirements

  • Compute the population mean and standard deviation along the selected axis
  • Preserve dimensions during reductions so values broadcast back to X
  • Map every slice with standard deviation at most eps to zeros
  • Return a NumPy array of floating-point values

Constraints

  • X is a nonempty one-dimensional or two-dimensional numeric list
  • axis is 0 for one-dimensional inputs and either 0 or 1 for two-dimensional inputs
  • eps is positive
  • Use NumPy only
Try Similar Problems
Min Max ScalingRobust ScalingLog TransformRank TransformMatrix Normalization

Sign in to take notes on this problem

Case 1

Accepts: array

Accepts: number

Accepts: number

You must run your code first.