![]() |
Array Dimensions - NEWBIE - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Array Dimensions - NEWBIE (/thread-25805.html) |
Array Dimensions - NEWBIE - willowman - Apr-12-2020 Hi all, I'm looking at a problem in structural dynamics. I need to do a what I thought would be a fairly simple calculation of a 3x3 array transposed multiplied by a 3x1 array. For this should give a 3x1 array as an answer. My 3x3 array is written as: Phi = np.array([[phi11, phi12, phi13],[phi21,phi22, phi23],[phi31, phi32, phi33]]) print (Phi) returns the below. [[ 1.00000000e+00 -1.42326796e-16 7.80310099e-17] [-1.65973033e-16 1.00000000e+00 3.72108258e-16] [ 2.64471834e-17 3.72043002e-16 1.00000000e+00]] My 3x1 array is written as: F = np.mat([0,791.7770505,-39.35299453]).reshape([3,1]) print (F) returns the below: [[ 0. ] [791.7770505 ] [-39.35299453]] However, when I make the multiplication modalF = np.array(Phi.transpose()*F) and print (modalF), the result is [[ 2.82809468 2.67362901 -4.03442266]] which is a 1x3 matrix??? I made a check of print(Phi.transpose().shape) print(modalF.shape) and the output is (1, 3, 3) (1, 3) Therefore I am confused on two counts: 1. Why is there 3 dimensions for Phi.transpose()? 2. Why is a 3x3 multiplied by 3x1 resulting in 1x3? Thanks in advance! Array Dimensions - NEWBIE - willowman - Apr-12-2020 Hi all, I'm looking at a problem in structural dynamics. I need to do a what I thought would be a fairly simple calculation of a 3x3 array transposed multiplied by a 3x1 array. For this should give a 3x1 array as an answer. My 3x3 array is written as: Phi = np.array([[phi11, phi12, phi13],[phi21,phi22, phi23],[phi31, phi32, phi33]]) print (Phi) My 3x1 array is written as:F = np.mat([0,791.7770505,-39.35299453]).reshape([3,1]) print (F) However, when I make the multiplicationmodalF = np.array(Phi.transpose()*F) print (modalF) which is a 1x3 matrix???I made a check of the dimensions of the input matrices and it seems that Phi.tranpose() is a 1x3x3 matrix? print(Phi.transpose().shape) print(modalF.shape) Therefore I am confused on two counts:1. Why is there 3 dimensions for Phi.transpose()? 2. Why is a 3x3 multiplied by 3x1 resulting in 1x3? Thanks in advance! RE: Array Dimensions - NEWBIE - perfringo - Apr-12-2020 I just provide a link which may help to understand numpy broadcasting rules: Array Broadcasting in Numpy. Documentation states: Quote:The term broadcasting describes how numpy treats arrays with different shapes during arithmetic operations. Therefore it is impossible 'to understand' arithmetic operations between numpy arrays of different shapes without understanding concept of broadcasting. |