Python Forum
Array Dimensions - NEWBIE
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array Dimensions - NEWBIE
#1
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!
Reply
#2
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) 
Output:
[[ 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) 
Output:
[[ 0. ] [791.7770505 ] [-39.35299453]]
However, when I make the multiplication
modalF = np.array(Phi.transpose()*F)

print (modalF)
Output:
[[ 2.82809468 2.67362901 -4.03442266]]
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)
Output:
(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!
Reply
#3
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie here. Create an array from file data? Rayj00 2 1,246 Jan-13-2023, 01:35 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020