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.
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:

need help with this python progam using numpy Create a 4x4 two dimensional array with numbers...
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...
By using two-dimensional array, write Python program to display a table that represents a Pascal triangle of any size. In Pascal triangle, the first and the second rows are set to 5. Each element of the triangle (from the third row downward) is the sum of the element directly above it and the element to the left of the element directly above it. See the example Pascal triangle(size=6) below: 5 5 5 5 10 ...
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 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...
Create an application that instantiates a 20?20 two-dimensional array of Date objects, populates it with random dates drawn from the range of 1/1/1970 to 12/31/2020, and then outputs the index and actual date of the row with the most recent date (relative to today) among all the rows and the index and actual date of the column with the oldest date (closest to 1/1/1970) among all the columns.
do it in python 1. Import the proper libraries: Pandas and NumPy and create aliases pd, np respectively. 2. Load sample data (car_loan.csv) into data frame: df 3. Export Pandas DataFrames to csv. Save file name as out.csv. hint: help(df.to_csv) 4. Run the command: df.info (). What do you see, how many columns? also what about number of entries for each column 5. It is often the case where you change your column names or remove unnecessary columns. a. Change...
For this lab, you will work with two-dimensional lists in Python. Do the following: Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(matrix, columnIndex) Write a function display() that displays the elements in a matrix row by row, where the values in each row are displayed on a separate line. Use a single space to separate different values. Sample output from this function when it...
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...
Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a statement that assigns 145 to the first column of the first row of this array. 2. Write a statement that assigns 18 to the last column of the last row of this array. values is a two-dimensional array of floats, with 10 rows and 20 columns. Write code that sums all of the elements in the array and stores the sum in the variable...
A two-dimensional square array of integers is a Latin square if the following conditions are true. The first row has no duplicate values. All values in the first row of the square appear in each row of the square. All values in the first row of the square appear in each column of the square. Examples of Latin Squares 10 30 200 0 20 30 10 30 0 10 20 20 10 0 30 Examples that are NOT Latin Squares...