4

Andrews Curves

Unsolved
Linear Algebra

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

Google

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]]

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

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

Get access to Premium only exclusive educational content available to only Premium users.

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.

Log in to post a comment

Comments
Jump to comment-143
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.

Jump to comment-158
noopur • 2 months, 4 weeks ago

0

Experiencing similar issue that output array was correctly obtained in the solution but here in the environment same is giving errors.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)