By Ayush Tripathi


2020-05-22 23:40:18 8 Comments

I am writing a program that includes taking a 2x2 input matrix from a file and returning the difference of the top-right and bottom-left value.

From one of the test cases, the input looks a little like this:

7 10
4 8

In this case, I would take 10 (top right) and 4 (bottom left), and then find the difference between the two (6).

Right now I am having trouble assigning variables to the numbers in the array using python. I've tried appending both lines into two lists and that didn't work.

I would appreciate it if anyone could point me in the right direction.

1 comments

@Changwenn Tok 2020-05-22 23:52:38

I tried to guess what you want, is this?

array_2d = [[7,10],[4,8]]

print(array_2d[0][1] - array_2d[1][0])

# assign new value
array_2d[0][0] = 30
array_2d[0][1] = 40
array_2d[1][0] = 50
array_2d[1][1] = 60      

Related Questions

Sponsored Content

27 Answered Questions

[SOLVED] How do I concatenate two lists in Python?

16 Answered Questions

[SOLVED] How do I copy a file in Python?

20 Answered Questions

[SOLVED] Are static class variables possible in Python?

38 Answered Questions

[SOLVED] How to get the current time in Python

  • 2009-01-06 04:54:23
  • user46646
  • 3291099 View
  • 2878 Score
  • 38 Answer
  • Tags:   python datetime time

44 Answered Questions

[SOLVED] How do I merge two dictionaries in a single expression in Python?

26 Answered Questions

[SOLVED] How do I pass a variable by reference?

22 Answered Questions

[SOLVED] Peak detection in a 2D array

11 Answered Questions

[SOLVED] How to access environment variable values?

16 Answered Questions

[SOLVED] What is a mixin, and why are they useful?

Sponsored Content