np.transpose doesn't return transpose of matrix

np.transpose doesn't return transpose of matrix



When I write my code in the following manner :


from numpy import *
H = array([1,1])
Ht = transpose(H)
Ht



I get the same matrix as H instead of the transpose of H.



But when I change the matrix H in the following way :


from numpy import *
H = array(([1,1],[2,3]))
Ht = transpose(H)
Ht



I get the transpose of H.



I fail to understand what is happening here. Is it the way transpose function is used or is it the way a matrix is defined?




2 Answers
2



I think this is the behavior you're looking for:


>>> H = np.array([[1,1]])
>>> H.T
array([[1],
[1]])



Equivalently you can write np.transpose(H). Notice this array has shape (1,2), so it has two dimensions. The array H = np.array([1,2]) has shape (2,). It only has one dimension. To swap the dimensions (transpose), you need at least two of them.


np.transpose(H)


(1,2)


H = np.array([1,2])


(2,)



From the documentation:



numpy.matrix.transpose. Returns a view of the array with axes transposed. For a 1-D array, this has no effect. (To change between column and row vectors, first cast the 1-D array into a matrix object.)





When I use the following: matrix('[1, 2; 3, 4]') It says 'list' object is not callable
– Dhruv Thakkar
Aug 26 at 9:07






You have called a variable matrix and assigned a list to it. That is why from numpy import * is a bad idea.
– BoarGules
Aug 26 at 9:42


matrix


from numpy import *






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế