2

Unit Length Scaling

Unsolved
Fundamentals

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

Amazon
Apple
Facebook
Google
Netflix

Data scaling is an important part of data preprocessing. Unit Length Scaling is the process of scaling the components of a feature vector such that  complete vector has the length one. Each point in scaled arr can be calculated as: 

\(x' = {x \over ||x||}\)

Write a function unitLengthScaling(x) which scales the input array (1D list) using Unit Length Scaling. 

Sample Input:
<class 'list'>
x: [100, 50, 10, 9]

Expected Output:
<class 'list'>
[0.8880210257451364, 0.4440105128725682, 0.08880210257451364, 0.07992189231706227]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Ipsam non maiores exercitationem voluptatem ullam sint voluptates commodi delectus. Inventore voluptatibus vel? Dolorem expedita harum tenetur impedit quod adipisci, aliquid quam iusto aperiam, dicta sed amet iusto officia? Eaque accusamus pariatur eos odit voluptas dolore ab quae optio?

Recusandae iste expedita deleniti totam magni in eveniet corporis eius nulla. Ad vero rerum harum excepturi? Quasi neque rerum, eius sint laudantium neque voluptatum rem nemo dignissimos necessitatibus accusamus architecto, culpa ab modi suscipit perferendis eveniet, ex sunt ipsa voluptatum quos minus?

Nam cumque quasi excepturi laborum officiis aliquid illo sapiente sit ea. Earum nobis aspernatur eligendi porro ad alias nulla minima exercitationem.

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

Ready.

Input Test Case

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