4

Andrews Curves

Unsolved
Linear Algebra

Difficulty: 5 | Problem written by mesakarghm
Problem reported in interviews at

Andrews curves are a method for visualizing multidimensional data by mapping each observation onto a function.

The function is defined as:

$$f_x(\theta) = {x_1 \over \sqrt 2} + x_2 \sin(\theta) +x_3\cos(\theta) + x_4 \sin(2\theta) + ...$$

For a given data, calculate and return the values for fx. Here the inputs will be a matrix in 2 dimensions (M), and a range of values for theta (m). The function should output a list with length m, such that each list element represents the value of andrews function over the column of that index in input matrix (mat).

Sample Input:
<class 'numpy.ndarray'>
M: [[17 24 1 8 15] [23 5 7 14 16] [ 4 6 13 20 22] [10 12 19 21 3] [11 18 25 2 9]]
<class 'int'>
m: 3

Expected Output:
<class 'numpy.ndarray'>
[[26.02081528 28.02081528 26.02081528] [25.26345597 39.26345597 25.26345597] [11.82842712 37.82842712 11.82842712] [-8.92893219 29.07106781 -8.92893219] [-8.22182541 41.77817459 -8.22182541]]

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Have an issue, the MLPro support team is available 24X7 to Premium users.

This is a premium feature. To access this and other such features, click on upgrade below.

abhishek_kumar • 3 months, 1 week ago

1

Hey! Anyone can please explain the last line.....

*****The function should output a list with length m, such that each list element represents the value of andrews function over the column of that index in input matrix (mat).**********

I'm getting weird error: ValueError:operands could not be broadcast together with shapes (2,3) (3,3)

BUT, same code is running properly in collab but with different Ouput value.