﻿ NumPy: Get the qr factorization of a given array - w3resource

# NumPy: Get the qr factorization of a given array

## NumPy: Linear Algebra Exercise-17 with Solution

Write a NumPy program to get the qr factorization of a given array.

Sample Solution:

Python Code :

``````import numpy as np
a = np.array([[4, 12, -14], [12, 37, -53], [-14, -53, 98]], dtype=np.int32)
print("Original array:")
print(a)
q, r = np.linalg.qr(a)
print("qr factorization of the said array:")
print( "q=\n", q, "\nr=\n", r)
``````

Sample Output:

```Original array:
[[  4  12 -14]
[ 12  37 -53]
[-14 -53  98]]
qr factorization of the said array:
q=
[[-0.21199958 -0.27930103  0.93650794]
[-0.63599873 -0.68815735 -0.34920635]
[ 0.74199852 -0.66964945 -0.03174603]]
r=
[[ -18.86796226  -65.4018692   109.39178122]
[   0.            6.67798664  -25.24309237]
[   0.            0.            2.28571429]]
```

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

﻿

Inviting useful, relevant, well-written and unique guest posts
{"ft_lang_label":"__label__en","ft_lang_prob":0.6534892,"math_prob":0.9644188,"size":1586,"snap":"2019-51-2020-05","text_gpt3_token_len":462,"char_repetition_ratio":0.11883692,"word_repetition_ratio":0.045081966,"special_character_ratio":0.37200505,"punctuation_ratio":0.18481848,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9945807,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-27T03:45:28Z\",\"WARC-Record-ID\":\"<urn:uuid:b0c6de2b-e0b3-4d88-a1ce-b9c4ff6e1609>\",\"Content-Length\":\"111576\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:802b60e5-7678-4de8-bc69-973f989ffeba>\",\"WARC-Concurrent-To\":\"<urn:uuid:8f0b2025-a7ce-4c53-8df6-1d27699b884e>\",\"WARC-IP-Address\":\"104.26.14.93\",\"WARC-Target-URI\":\"https://www.w3resource.com/python-exercises/numpy/linear-algebra/numpy-linear-algebra-exercise-17.php\",\"WARC-Payload-Digest\":\"sha1:OXQIVFS4P7L74RGR5SO76GKT3P45NZL7\",\"WARC-Block-Digest\":\"sha1:II5M3H4DCVXHG4UG3PV4JEYRDGGJIQS5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251694176.67_warc_CC-MAIN-20200127020458-20200127050458-00267.warc.gz\"}"}