Question

Develop a python program to - Create a 2D 10x10 numpy array and fill it with...

Develop a python program to

- Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9).

- Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array.

- Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values you visited.

- Call the function 3 times to show current the sum.

Note 1: 2D numpy array will be created and randomly filled just once.

Note 2: You cannot move out of array, up, or left.

Homework Answers

Answer #1

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import numpy as np

def print_sum(array):
    sum_array = 0
    pos_x = 0
    pos_y = 0
    while pos_x!=9 and pos_y!=9:
        if pos_x == 9:
            pos_y += 1
        elif pos_y == 9:
            pos_x += 1
        else:
            value = np.random.randint(0,2)
            if value == 0:
                pos_x += 1
            else:
                pos_y += 1
        sum_array += array[pos_x][pos_y]
    print("\nSUM is: ",sum_array)

array = np.random.randint(1,10, size=(10, 10))
print("Original Array:")
print(array)
print_sum(array)
print_sum(array)
print_sum(array)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions