At Westonci.ca, we provide reliable answers to your questions from a community of experts. Start exploring today! Join our platform to get reliable answers to your questions from a knowledgeable community of experts. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
Sagot :
Answer:
(1) The program in Python is as follows:
rows, cols = (3, 3)
arr =[[0,0,0],[2,2,2],[-2,-2,-2]]
print(arr)
arr[0][0] = 10
arr[2][2] = -10
print(arr)
for i in range(rows):
for j in range(cols):
arr[i][j]-=2
print(arr)
for i in range(rows):
for j in range(cols):
if arr[i][j]< 0:
print(arr[i][j], end = ", ")
(2) The program in Python is as follows:
import numpy as np
x = [10000, 1000, 100, 10, 1, 0, -10, -100]
p = [0.05, 0.05, 0.20, 0.20, 0.1, 0.1, 0.1, 0.2]
q = np.dot(x,p)
print(q)
Explanation:
(1)
This initializes the rows and columns of the array to 3
rows, cols = (3, 3)
1. This creates and array and also populates it with the given data
arr =[[0,0,0],[2,2,2],[-2,-2,-2]]
Print the array
print(arr)
2. This changes index 0,0 to 10 and index 2,2 to -10
arr[0][0] = 10
arr[2][2] = -10
Print the array
print(arr)
This iterates through the rows and the columns of the array
for i in range(rows):
for j in range(cols):
3. This subtracts 2 from each array element
arr[i][j]-=2
Print the array
print(arr)
This iterates through the rows and the columns of the array
for i in range(rows):
for j in range(cols):
If array element is negative
if arr[i][j]< 0:
4. Print the array element
print(arr[i][j], end = ", ")
(2)
Line 1 and 2 are given as part of the program
x = [10000, 1000, 100, 10, 1, 0, -10, -100]
p = [0.05, 0.05, 0.20, 0.20, 0.1, 0.1, 0.1, 0.2]
This uses np dot to multiply x and p
q = np.dot(x,p)
This prints the result of the product
print(q)
Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. Westonci.ca is your trusted source for answers. Visit us again to find more information on diverse topics.