Adobe Scan Sep 03 2024
Adobe Scan Sep 03 2024
are either
There
arrays
Date: Score: a in NumPy
Intermediate at
valuetype.arrays
Hence
(length-1).
one same arrays.
create ordered.
Exercises
Programming
Based than
theto with
moreof is are to
account. list 0from
index.
elements working
Numpy Arrays negative
hold to: library the range
expected
and Colab in
Numpy can of for Python
with
NumPy elements a
of functions
3: whichnumber
used ListsPython
Google
Indices using Eng
Exercise
to
Introduction variable,the
library
are Python
students default
their
i.e.,subscript.
back
the
tist.
a Syntax:
list_name[start:stop:step] Bios
fixed object, of
of a with sub-sequence
from odd_num[0:5])
a One is in to odd_num:5]))
hold Numpy
special the themselves
arrays
arays in or
sequence print("List
elements:",
odd_num[0])
accessed
print("List
elements:",
odd_num[-1) odd_num) 0
arrays. log index index
Laboratory
and
Python a
can
is than1D-4D
integers.
chapter,
codecode
to to
need Slicing:
and
Indexing
using
_num)
Odd_num=
(1,3,5,7,9,11,13,15]
odd extractinga
odd_num
=[1,3,5,7,9,11,13,15]
assumes
elements:",
:",
&
Agri
Section: Introduction
Python this
Familiarize
to Methodology isa be are:",
Objectives will accessed elements:",also elements
structure ableable
Be list of
in signed
array, lists of student a index
elements
Arays in end Be Indexing:
can Engi
& Arrays of than elements is fivestartfive
Level the
data bit are
elements Slicing Unt
and types The print("List print("First
Name: 64 faster At Example:
# print("List
slicing
print("First
#omitting
Year Lists a or III.
is four32 are I. #list lMin
t
of
Cen
Colle
subscript using
done
-first
be
subscripts Can
list.
a colors)
two of
position
requires
list. nested_list[OJ2)
odd_num[0:5:2) list) beginning,:"
odd_num[5:]) len(nested inner nested_list[1:])
any pandavas)
object. objects
the colors) pandavas)
at pandavas)"Arjun"]
odd_num[-5:]) Falsel] for
is:",
inserted "Arjun"]
elements
list :", list list:", listssubscriptnested_list[2]) appending:",the pandavas.extend
(["Nakul",
"Sahadev"]) ",
print("Concatenat
pandavas+12)
of fifth [True, nested list elementare:" be extend
at extending:", "Bheem",concatenation
"Bheem",
end:"
onwards a
of colors) inserting
more
extending:", 2)
element the
asSumesto up elements:" "Arjun", nested
second element first can
objects: ",
elementsfiprint("Last
ve
print("Alternative in
elementsslicing
of list
first than Element
or or Dharmaraj",
concatenati
element lists is:", the are:",
insert "Green"]
=["Red", after
colors
element
after oneDharmaraj",
before
12
=["Nakul",
"Sahadev"]
index index #using -an [[1,2,3),
negative -nested the of
slicingfirstof of other Lists element
#Appending
colors.insert(0,"White")
colors.append("Blue") after List after
element member
elements or
Insertion:
element
elements elements elements with #concatenation
Lists list) and and
print(nested_
of of on append first
stop5thsize
step
#using print("Number member print("Elements list print("Pandavas
print("Pandavas print("pandavas
print("From
omitting
NestedLists
list
list and
Indexing
print("Third
outer Indexing print("Third
Methods
an as
Inserting
print("List
the
["
=
print("Listpandavas
["
=
pandavas
after
two print("List
of
nested_ Third 1.
append Extend print("2
#List the last
# for # # # # # #
to
commands
num)
slice
even_num)
even and keyword
Engi
", even_num) type()
even_num)
2: dtype
:, index even_num) the
element use the Bios
)even_num.pop()
at del:", pop:"
element and use
list even_num)
_num) deletion:" Lists array,dtype=np.float32)
np.array([1,2,3,4],
X=
the last using using list list. &
from poppingpopping float Python Python resulting
Ag
even index index the 9])
element 4deletion:",
(2,even_num=
,6,8,4,10] [2,4,6,8,4,10]
even_num=
element:, =[2,4,6,8,10,12]
even_num
before 3rd
and in L]
in
8,
7, from
1the
specified
even_num.
deletion remove(4)after after
:",
elements at at
3rd is
int, type
string,
item in
Arrays 6,
5, Arrays np 3])
before the
of
of
PE
elements elements
even_num.pop(2) deletiondeletion data 4] L)A=array.array('t,
before even_num.pop(3)
even_num[3]
del 3.0,for Fixed-Type 4,
list(range(10))
L= 3,
5,
2, 3.14
type
after method
#pop Deleted Print[type(item) as
Creating
a NumPy what "2", 1, array4,
numpy#nteger
np.array((1, data
Deleteaprint("List
print("List print("List
method
#del print("After Create
print("After
print("List print("List #Example:
determine
import
array (0, putting
L=[True, Array('t, the print(X)
print(' Import
#try set
# A To
array
#make a multidimensional
y=np.array([range(i, i+3) for l in (2,3,6))
print(y)
Try yourself:
array filled with Os
8. Create a length-10integer filled with 19
point array
b. Create a 3x5 floating
filled with 3.14
C. Create a 3x5 array
a linear sequence
d. Create an array filled with and 1
values evenly spaced between 0
e. Create an array of five distributed
f. Create a3x3 array of uniformly
distributed pseudorandom
g. Create a 3x3 array of normally
integers in the interval 0, 10
h. Crate a 3x3 array of pseudorandom
i. Create a 3x3 identity matrix
#math operations
print("x3 ndim:", x3.ndim)
ADEAB: computer Applleationn in AB Engineering
Multidimensional Subarrays
X2
Colloge ofEngineering
Central Mindanao Dopartrnernt of
University &
x2 sub=x2[:2, :2]
print(x2_sub)
#modifysub array
x2_sub[0,0]=99
print(x2sub)
print(x2)
method
Reshaping arrays - can be done using the reshape
np.concatenate([grid, grid])
#concatenate along the second axis (zero-indexed)
np.concatenate([grid, grid], axis = 1)
grid= np.arange(16).reshape((4,4)
grid
Functions
Computational on NumPy Arrays: Universal
operations
Universal functions (ufuncs)- implements vectorized
import numpy as np
rng = np.random.default_rnglseed=1701)
def compute_reciprocals(values):
output = np.empty(len(values)
for iin range(len(values)):
output[i] =1.0 /values[i]
return output
Ufuncs
print(compute_reciprocals(values)
print(1.0/values)