Question

In: Computer Science

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.

Solutions

Expert Solution

##IF YOU ARE SATISFIED WITH THE CODE, KINDLY LEAVE A LIKE, ELSE COMMENT TO GET YOUR DOUBTS CLEARED

CODE:

#FUNCTION TO CALCULATE SUM:

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)

#driver code:

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

OUTPUT:


Related Solutions

PYTHON Given a 2D array with the layout of the floor of a concert hall and...
PYTHON Given a 2D array with the layout of the floor of a concert hall and the height (in dwillyinches, a logarithmic measurement of height) of each concert attendee, write a program that determines if every attendee can see the front stage. An attendee can see the front stage if they are strickly taller than all of the attendees in front of them. Everyone can see the front-stage in the example below: # FRONT STAGE [[1, 2, 3, 2, 1,...
Submit a well-commented C program.   Create code. That will build a random 8x8 2D array of...
Submit a well-commented C program.   Create code. That will build a random 8x8 2D array of small-case characters. Demonstrate how it functions by printing out the result on your screen. Add a function will print out a single line of the array. If the user enters a value between 0 and 7 to select to print out a single row of the original 2D array.                void printLine(char *,int);    // This is the prototype declaration             void printLine(char myArr[][])     //...
1) Load the data from lab6_precipitation.csv into a numpy array; 2) Make a numpy array with...
1) Load the data from lab6_precipitation.csv into a numpy array; 2) Make a numpy array with the years 1916-2016 and dtype=int; 3) Make a numpy array with the months 1-12 and dtype=int; 4) Print out the shape of the data array and the lengths of the years and month array. If the length of your year array does not equal the number of rows in your data array, or the length of your months array does not equal the number...
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
Use NumPy to create a My_Array; a 3 by 3 array where in,m = n +...
Use NumPy to create a My_Array; a 3 by 3 array where in,m = n + m. (e.g., the first row first column would be 0+0=0, second row first column would be 1+0=1, etc). complete the following using NumPy: Compute the mean, median, range, and variance of this array Find the inverse or pseudo inverse Find the determinant Perform the following operations on My_Array Create My_1D_Array by reshaping My_Array into a 1-dimensional array Create a new array that is the...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program quiz could be of anything like , what's the sum of 2&2. There should be number of attempts(limited) suppose if the answer is wrong.
The goal is to Create an array of struct “employee” Fill the array with information read...
The goal is to Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make use of the random_shuffle() function from the standard algorithm library. You can use srand() function provided in with a seed...
i want a program in java that finds the shortest path in a 2D array with...
i want a program in java that finds the shortest path in a 2D array with obstacles from source to destination using BFS and recursion. The path must be stored in a queue. The possible moves are left,right,up and down.
#Python program using loop instead of numpy or pandas. Write a function to enter n student...
#Python program using loop instead of numpy or pandas. Write a function to enter n student scores from 0 to 100 to represent student score, Count how many A (100 - 90), B(89-80), C(79-70), D(69-60), F(<60) We will use numpy array OR pandas later for this problem, for now use loop Invoke the function with 10 student scores, show the result as follow: Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT