Question

need help with this python progam using numpy Create a 4x4 two dimensional array with numbers...

need help with this python progam using numpy

Create a 4x4 two dimensional array with numbers from 1 thru 16.

show this then:

Change the last element by dividing it in half. Show that the original array has changed.

show this then:

Set all values in row 2 to zero. Show the original array contains this change

show this then:

Set all values in column 1 to one. Shoe the original array contains this change.

show this then:

Display the product of the first and third columns.

show this then:

Display the sum of the first and second rows.

then do:

Set the 4 elements in the center of the array to 99 and display the original data to show the change.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code:

import numpy as np

rows = 4

cols = 4

# Create a 4x4 two dimensional array with numbers from 1 thru 16.

a = np.zeros((rows, cols))

counter = 1

for i in range(0, rows):

for j in range(0, cols):

a[i][j] = counter

counter += 1

print(a)


# Change the last element by dividing it in half. Show that the original array has changed.

print("\nChange the last element by dividing it in half.")

a[rows-1][cols - 1] /= 2

print(a)

# Set all values in row 2 to zero. Show the original array contains this change

print("\nSet all values in row 2 to zero.")

for i in range(0, cols):

a[2][i] = 0

print(a)

# Set all values in column 1 to one. Shoe the original array contains this change.

print("\nSet all values in column 1 to one.")

for i in range(0, rows):

a[i][1] = 0

print(a)

# Display the product of the first and third columns.

print("\nthe product of the first and third columns.")

for i in range(0, rows):

print(a[i][0] * a[i][2])

# Display the sum of the first and second rows.

print("\nthe sum of the first and second rows.")

for i in range(0, cols):

print(a[0][i] * a[1][i])

# Set the 4 elements in the center of the array to 99 and display the original data to show the change.

print("\nSet the 4 elements in the center of the array to 99.")

a[1][1] = 99

a[1][2] = 99

a[2][1] = 99

a[2][2] = 99

print(a)

Output:

Add a comment
Know the answer?
Add Answer to:
need help with this python progam using numpy Create a 4x4 two dimensional array with numbers...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python import numpy as np Given the array a = np.array([[1, 2, 3], [10, 20,...

    In Python import numpy as np Given the array a = np.array([[1, 2, 3], [10, 20, 30], [100, 200, 300]]), compute and print the sums over all rows (should give [6, 60, 600]) the sums over all columns (the sum of he first column is 111) the maximum of the array the maxima over all rows the mean of the sub-array formed by omitting the first row and column the products over the first two columns (hint: look for an...

  • Programing in Scala: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point...

    Programing in Scala: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers. Write separate methods to get an element (given parameters row and col), set an element (given parameters row, col, and value), and output the matrix to the console formatted properly in rows and columns. Next, provide an immutable method to perform array addition given two same-sized array.

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array...

    java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array of 1000 integers. Name the array: x 2. Assign 95 to the ninth element, 25 to the twentieth element of array x. 3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x. 4. Display the sixtieth element of the array. 5. Use the for statement to generate all indexes to read and display all elements in...

  • An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and ...

    An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and 1≤j<l≤n , we have >A[i,j]+a[k,l]≤A[i,l]+A[k,j]> In other words, whenever we pick two rows and two columns of a Monge array and consider the four elements at the intersections of the rows and columns, the sum of the upper-left and lower-right elements is less than or equal to the sum of the lower-left and upper-right elements. For example, the following...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

  • Write the line that declares a two-dimensional array of strings named chessboard. That is, how would...

    Write the line that declares a two-dimensional array of strings named chessboard. That is, how would I declare a two-dimension array of strings that is called chessboard? You would declare a String array by saying " String []" correct? Now that's just a single array. How can I make that a two-dimension array? And how would I name it chessboard? Write the line that declare and creates a two-dimensional array of chars, tictactoe, with 3 rows, each with 3 elements...

  • I'm a little crunched for time and need some help with these first two questions. Thank...

    I'm a little crunched for time and need some help with these first two questions. Thank you! Question 1.) Write a Java program that reads in sequence of integers from the user until user enters a negative number and stores them in an Integer ArrayList. Once read, display a bar chart based on the values stored in the ArrayList. For example, if the user inputs 2, 5, 3, 8, 4, and -1, then your program should display the bar chart...

  • D Question 12 1.5 pts Check the true statements about NumPy arrays: O A single instantiated NumPy array can store multi...

    D Question 12 1.5 pts Check the true statements about NumPy arrays: O A single instantiated NumPy array can store multiple types (e.g., ints and strings) in its individual element positions. A NumPy array object can be instantiated using multiple types (e.g., ints and strings) in the list passed to its constructor O Memory freeing will require a double-nested loop. The number of bits used to store a particular NumPy array object is fixed. O The numpy.append(my.array, new_list) operation mutates...

  • Python Help: Using the stock.py data, write a program that does the following: Create a NumPy...

    Python Help: Using the stock.py data, write a program that does the following: Create a NumPy array from the nasdaq list from stocks.py. Do the same with the other three lists from stocks.py. Thus, at the end of this tasks, you will have four NumPy arrays. Print out the type (that is, the object type, not the element type) of each array in #1 and the data type typecode of the elements in each array in #1. This task is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT