0% found this document useful (0 votes)
9 views2 pages

ChE112 Midterms Part1

The document contains Python code using NumPy to create and manipulate arrays. It demonstrates creating a 3x3 array, copying and modifying it, extracting the diagonal, and creating zero and filled arrays. Additionally, it shows how to compute the dot product of two arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

ChE112 Midterms Part1

The document contains Python code using NumPy to create and manipulate arrays. It demonstrates creating a 3x3 array, copying and modifying it, extracting the diagonal, and creating zero and filled arrays. Additionally, it shows how to compute the dot product of two arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [63]: import numpy as np

In [65]: A = np.array([[1, 2, 3],


[4, 5, 6],
[7, 8, 9]])
display(A)

array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])

In [67]: B = A.copy()
B[0] = A[2]
B[1] = A[1]
B[2] = A[0]

display(B)

array([[7, 8, 9],
[4, 5, 6],
[1, 2, 3]])

In [69]: d = np.diag(A)
display(d)

array([1, 5, 9])

In [71]: C = np.zeros((5, 5))


display(C)

array([[0., 0., 0., 0., 0.],


[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]])

In [73]: D = np.full((5, 5), -0.5)


print(D)

[[-0.5 -0.5 -0.5 -0.5 -0.5]


[-0.5 -0.5 -0.5 -0.5 -0.5]
[-0.5 -0.5 -0.5 -0.5 -0.5]
[-0.5 -0.5 -0.5 -0.5 -0.5]
[-0.5 -0.5 -0.5 -0.5 -0.5]]

In [75]: v = np.array([1, 2, 3])


u = v
w = np.array([4, 5, 6])

display(v)
display(w)

dot_product = np.dot(v, w)

print(dot_product)
Loading [MathJax]/extensions/Safe.js
array([1, 2, 3])
array([4, 5, 6])
32

In [ ]:

Loading [MathJax]/extensions/Safe.js

You might also like