473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need to help in create the matrix AxB in python

I need to create matrix AxB
The requirement is as sample below
This is the 5x10 matrix that I need

Expand|Select|Wrap|Line Numbers
  1. [1.0, 0.0, 0.0, 0.0, 0.0],
  2. [-1.0, 0.0, 0.0, 0.0, 0.0],
  3. [0.0, 1.0, 0.0, 0.0, 0.0],
  4. [0.0, -1.0, 0.0, 0.0, 0.0],
  5. [0.0, 0.0, 1.0, 0.0, 0.0],
  6. [0.0, 0.0, -1.0, 0.0, 0.0],
  7. [0.0, 0.0, 0.0, 1.0, 0.0],
  8. [0.0, 0.0, 0.0, -1.0, 0.0],
  9. [0.0, 0.0, 0.0, 0.0, 1.0],
  10. [0.0, 0.0, 0.0, 0.0, -1.0]
Would anyone help me in this case?

I have tried with
Expand|Select|Wrap|Line Numbers
  1. test_matrix = [[0.0 for i in range(5)] for i in range(10)]
  2.  
  3. for d1 in range(5):
  4.     test_matrix[d1][d1] = 1.0
But it create as
Expand|Select|Wrap|Line Numbers
  1. [1.0, 0.0, 0.0, 0.0, 0.0],
  2. [0.0, 1.0, 0.0, 0.0, 0.0],
  3. [0.0, 0.0, 1.0, 0.0, 0.0],
  4. [0.0, 0.0, 0.0, 1.0, 0.0],
  5. [0.0, 0.0, 0.0, 0.0, 1.0],
  6. [0.0, 0.0, 0.0, 0.0, 0.0],
  7. [0.0, 0.0, 0.0, 0.0, 0.0],
  8. [0.0, 0.0, 0.0, 0.0, 0.0],
  9. [0.0, 0.0, 0.0, 0.0, 0.0],
  10. [0.0, 0.0, 0.0, 0.0, 0.0]
May 13 '16 #1
1 1315
Here is the solution

Expand|Select|Wrap|Line Numbers
  1. matrix_test = [[0.0 for i in range(5)] for i in range(10)]
  2. for x in range(5):
  3.     matrix_test [2 * x][x] = 1.0
  4.     matrix_test [2 * x + 1][x] = -1.0
May 13 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Active8 | last post by:
I did this once and can't remember how <blush> so I read the reportlab user guid. It says to unzip the reportlab archive - this is on w2k, BTW, with Python23 - to a directory and make a file...
2
by: Polyhedron_12 | last post by:
I am having problems calling functions in general in VB. I keep getting alot of errors. Can anybody help me out with this? I put the error message on the same line that it says it is at. I believe...
1
by: sunlight_sg | last post by:
Hello, i am using ADOX + VB .NET to create a Access Database programmatically. I plan to set some properties of the column such primary key. The code is as follows: Dim cat As ADOX.Catalog...
6
by: GHUM | last post by:
I need to split a text at every ; (Semikolon), but not at semikolons which are "escaped" within a pair of $$ or $_$ signs. My guess was that something along this should happen withing csv.py;...
1
by: KraftDiner | last post by:
Could someone point me to step by step instructions on building boost python on mac os x? I have bjam running.. I have the boost source... but the tests are failing.. Probably something to do...
5
by: Budiman | last post by:
Hello friends, i need help for my assignment. For example i give input for a, b, c, d in matrix mode example like |a b| |c d| and i want to convert it to invers from that matrix, i hope...
6
by: PythonBiter | last post by:
Hi everyone, I'm very new in this Group as well Python language. I want to learn Python. So could you please advice me, and guide me how can i become master in Python ! Thanks, Partha
2
by: Sells, Fred | last post by:
Diez wrote... You're right the ctypes does seem more pythonesque; however I'm still stuck trying return all these parameters that the c api uses. my ctypes code is below. It just quits running...
22
by: Chuck Connors | last post by:
Hey guys. I'm working on a little program to help my wife catalog her/ our coupons. I found a good resource but need help formatting the text data so that I can import it into a mysql database....
7
by: victory2006 | last post by:
i need help to make a board such as this: -----------Col 0--Col 1--Col 2 Row 0------1------1--------0 Row 1------0------0--------1 Row 2------1------1--------1 (Please ignore the dashes,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.