I am very new to Python and struggling to find a way to enter a matrix of data. What I need to do is:
- Ask user how many rows
- Ask user how many columns 3 Enable user to type in 1 or 0 values for the specified row x column matrix
I'm actually trying to replicate what was previously undertaken in an old PCW BASIC program! In that version, the user was asked to type a 1 or 0 individually, i.e for a 3 x 3 matrix they would be asked to enter Row 1, Col 1? [Enter] Row 1, Col 2 [Enter] Row 1, Col 3 [Enter] Row 2, Col 1 [Enter] .... etc.
Ideally it would be better if the user was able to type one complete row at a time, i.e 1 0 1 [Enter] 1 1 0 [Enter] 0 1 0 [Enter] or even better in a spreadsheet-like grid but I suspect that is too ambitious for someone just starting out in Python. For each matrix the user would first have entered row and column title labels so it would be preferable to show these in the screen output once the data has been entered.
Beyond this stage there is a series of fairly basic mathematical operations to be completed on the data.
From my initial reading I initially got the impression that I might need to use NumPy or pandas? I have read a bit about these but can't see anything which fairly closely resembles what I am trying to achieve. Now I'm beginning to think that Lists may suffice?
If anyone can help point me in the right direction or give me a few pointers that would be much appreciated.
To illustrate what I'm trying to replicate, this is an extract from the original BASIC code:
1100 INPUT "HOW MANY ELEMENTS (COLUMNS) HAVE YOU"J
1110 PRINT
1120 INPUT "HOW MANY VARIABLES (ROWS) HAVE YOU"I
1130 PRINT
1140 PRINT "INPUT DATA,ROW BY ROW,AS FOLLOWS:"
1150 PRINT "TYPE '0' FOR A VOID"
1160 PRINT "TYPE '1' FOR AN INCIDENT"
1170 PRINT
1180 FOR R = 1 TO I
1190 FOR C = 1 TO J
1200 PRINT "ROW "R;": COLUMN "C;
1210 INPUT "INCIDENT OR VOID"R%(R,C)
1220 NEXT C
1230 NEXT R
Thanks very much!
Robert