Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Matrix Assignment
#1
Dear everybody
I am very expert with MATLAB programming but I am new with Python.
Very simple matrix assignment which is worked well in MATLAB, does not work in Python.
import numpy as np

x = np.zeros([100,2,20])
y = np.random.binomial(1,0.5,size=[100,1,20])

x[:,0,:] = y
Please help.
P.S. Please don't change the dimension of x and y. I need both of them 3D.
Reply
#2
I don't get what you are trying to do on line 6. Could explain that part?
Reply
#3
(Aug-02-2019, 08:06 PM)SheeppOSU Wrote: I don't get what you are trying to do on line 6. Could explain that part?

Simply, I am trying to copy y in the first column of x
Please note that x and y are 3D matrices.
x has 100 rows, 2 columns and 20 channels
y has 100 rows, 1 column and 20 channels
Reply
#4
I don't know for sure, but try x[0] = y[0]
Reply
#5
oups Blush not awaked
Reply
#6
(Aug-03-2019, 06:31 AM)SheeppOSU Wrote: I don't know for sure, but try x[0] = y[0]

wrong
Reply
#7
Could you explain what the line 6 means as in, why are there colons and a zero in the middle surrounded by brackets. If i understand what it means, I can probably translate it to Python code
Reply
#8
I guess the issue comes from the matrix size definition (the 3rd value seems not be the depth, isn't it?) , but I'm not familar with 3D arrays and I'm still missing some stuffs

Maybe can you find some tricks here

The following code is not you're expecting, but it may highlight some things
import numpy as np
 
x = np.zeros( (100,20,2) );
y = np.random.binomial(1, 0.5, size=[100,20,1]);
z = np.random.random((10, 20, 2));
x[:, :, 0] = y[:, :, 0];

print(x[:,:,0])
Paul
Reply
#9
(Aug-03-2019, 08:55 AM)SheeppOSU Wrote: Could you explain what the line 6 means as in, why are there colons and a zero in the middle surrounded by brackets. If i understand what it means, I can probably translate it to Python code

The 2nd dimension of x has 2 elements. I want to fill the first element by y.
Reply
#10
(Aug-04-2019, 11:49 AM)m_llaa Wrote: The 2nd dimension of x has 2 elements. I want to fill the first element by y.
The first element of the second dimension would look like "x[1][0]". 1 For the second dimension and 0 to get the first element. When I try "x[1][0] = y", I get an error. I don't get an error if I do "x[1][0] = y[1][0]", so is this what you are trying to do.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 820 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  Can't modify a simple matrix Lewkiy 3 903 Feb-05-2023, 02:59 PM
Last Post: Lewkiy
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,353 May-03-2021, 06:30 AM
Last Post: Gribouillis
  matrix from matrix python numpy array shei7141 1 3,693 Jan-16-2017, 06:10 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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