1

In my program, I generate two lists each with 10 integers: one through user input, and one through random selection. Then, using numpy, I convert one of the lists into a 2x5 array, and the other into a 5x2 array and take the outer product to arrive at a 5x5 array like this:

 [[ 1 1 1 1 1]
  [ 1 1 1 1 1]
  [ 1 1 0 1 1]
  [ 1 1 1 1 1]
  [ 1 1 1 1 1]]

I want to ask the user some questions about the array, for example, "What is the value in the center of the resulting array?" (which would be 0 in this case).

How can I have Python check the value of the integer at the center of the array?

2
  • possible duplicate of Checking elements in a matrix in python Commented Apr 27, 2014 at 18:02
  • @pez I like the way you describe your question - it is succinct an clear. Keep on going this way. Commented Apr 27, 2014 at 21:18

3 Answers 3

2

If your array is arr, arr[2,2] will return the 3rd value down and 3rd value across (because indexing starts with 0). See the documentation.

Sign up to request clarification or add additional context in comments.

Comments

1

Given the you are asking for the center, i am assuming that your array is going to have odd dimensions. if that is the case you could use the following:

print arr[len(arr)/2][len(arr[1])/2]

this divides the number of rows and columbs by 2 which will give you the middle index.

Comments

1

If your array is a square array with odd dimensions you can do

x.ravel()[x.size/2]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.