#30 Python Tutorial for Beginners | Copying an Array in Python
Vložit
- čas přidán 5. 09. 2024
- Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-sp...
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
Instagram : / navinreddyofficial
Linkedin : / navinreddy20
TELUSKO Android App : bit.ly/TeluskoApp
Discord : / discord
In this lecture we will see:
- Addition of values in an array
- Different functions that can be performed on arrays
- What is Aliasing in python?
- Different ways of copying an array
#1
- We can add any value in each element of an array.
- We can also add values of two arrays.
- The addition of two arrays is known as Vectorized Operation.
- We can also find the values of each element of an array of mathematical operations such as sin, cos, tan, log, sqrt etc.
- Sum of every element of an array can also be calculated by using the sum() function.
- Minimum value can also be get from an array through the min() function.
- Maximum value can be get from an array by using the max() function.
- Unique elements from an array and the sorted array can also be get.
- Concatenation of two arrays can also be performed by using the concatenate function. This function combines two arrays.
#2
- Two variables can be pointed towards a single array. It means both variables are pointing to the same memory address where the array is stored.
- In Python, Aliasing happens whenever one variable's value is assigned to another variable.
- view() is a function that helps to create a new array at a new location. It means arrays should be present at the different memory addresses.
- By using the view() functions, two variables will point towards two different arrays.
#3
- In python, two copying techniques are available i.e.,
1. Shallow Copy
2. Deep Copy
- In shallow copy, it will copy elements but it means both arrays are dependent on each other.
- In shallow copy, if we update an element in one array then the changes would also be reflected in another array.
- In a deep copy, two different arrays are not linked with each other in any way.
- In a deep copy, we use the function known as a copy() instead of using the view() function.
- copy() function provides a deep copy of an array.
Github :- github.com/nav...
Python for Beginners :- bit.ly/3JOLQhl
Java and Spring Framework For beginners with Spring Boot : - bit.ly/3LDMj8D
Java Tutorial for Beginners (2023) :- bit.ly/3yARVbN
Subscribe to our other channel:
Navin Reddy : www.youtube.co....
Telusko Hindi :
www.youtube.co....
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
www.telusko.com...
I am a mechanical engineer,
Just heard of this language, searched for online tutorials, guess what ? I count myself lucky to learn from your tutorial
Thanks sir,
Jazakallah khair 🙂
me too
me too royal mec
Sir, did you got software job
I'm also mechinal background
Not all superheroes wear capes, Some teach Python for free...
Hello Navin sir, Although i am from a software background, I always had this fear of coding and use to run away from it. Since i have started watching your videos now i feel confident and now i am beginning to write some lines of code on my own. Still long way to go! I have my MS studies coming up and i desperately needed to learn a language. I dont know how would i do that if i had not come across your channel. In kannada, there is a saying "Koti Koti Dhanyavadagalu" meaning countless thanks for changing my life :)
hey.. nanu kuda kannadiga bro :)
Waoh Sir Navin, who is like me in this am humbled to say I got 100% in this
Even I do
Hello Mr.Navin. Thank you so much for sharing valuable and interesting videos for us. I've started to learn Python by watching and practising your videos and everything is Ok.
finally I got deep and shallow copy from your videos....before I searched on web n didn't get ….thank you sir.....
from numpy import *
arr =array([1,2,3,4,25])
arr1=array([15,16,20,21,5])
for i in range(len(arr)):
arr[i]=arr[i]+arr1[i]
print(arr)
print("bye")
Bhai if length is not same means wt to do can u please guide me
@@madhankumarmr9968
from numpy import *
arr1=([3,7,8,4,3])
arr2=([8,3,9,6])
arr3=([])
for i in range(min(len(arr1),len(arr2))):
x=arr1[i]+arr2[i]
arr3.append(x)
print(arr3)
@@namanjain2320 cant append in numpy
Numpy doesn't support append method
i m a it student...and python is one of the trending languages...i went for too many channels on youtube...but i found urs is very helpful and relying...one of ur instructor helped through ur tutorials to make me learn javascript...keep it up you all guys u r doing great work and i always wish for your best guys...
thank you Sir : )
Ans:
1.
from numpy import *
array1 = ([])
array2 = ([])
size1 = int(input('Enter size of first array: '))
size2 = int(input('Enter size of second array: '))
print(f'Enter {size1} values in first in array: ')
for i in range(size1):
array1.append(int(input()))
print(f'Enter {size2} values in second array: ')
for i in range(size2):
array2.append(int(input()))
if size1 < size2:
for i in range(size1):
array2[i] = array1[i] + array2[i]
print(array2)
else:
for i in range(size2):
array1[i] = array1[i] + array2[i]
print(array1)
2.
from numpy import *
array = ([])
size = int(input('Enter size of array: '))
print(f'Enter {size} values in array: ')
for i in range(size):
array.append(int(input()))
max_value = array[0]
for i in range(1, size):
if max_value < array[i]:
max_value = array[i]
print(f'Maximum value = {max_value}')
Bhai ye print ke Baad f likha hai wo q likha hai (f'Maximum value ) isme jo f hai wo
Great!
your code doesn't work on my system bro, can you plz explain the code
This is not an Array, You are adding two lists. Check the type of variables 'array1' and 'array2'
bhai numpy main append attribute nahi ata hai
qn 1,
from numpy import *
arr1 = array([2,4,5,6])
arr2 = array([3,7,9,1])
for arr3 in (arr1 + arr2):
print(arr3)
qn2,
from numpy import *
arr = array([2,4,7,1,2])
max = 0
for i in range(len(arr)):
if(max
man, you're the best teacher I've come across. Best tutorials. Bought some paid ones on udemy, neither lived up to expectations. The content here, super.... Engaging delivery......
#1
from numpy import *
arr1 = array([5, 10, 15, 20, 30])
arr2 = array([55, 16, 1, 280, 60])
arr3 = []
k = 0
for num1 in arr1:
num3 = num1 + arr2[k]
arr3.append(num3)
k += 1
print(arr3)
#2
def find_max(array):
max_value = array[0]
for i in range(1, len(array)):
if array[i] > max_value:
max_value = array[i]
return max_value
array = [3, 5, 7, 2, 9, 4, 6]
print("The max value in the array is", find_max(array))
1) from numpy import *
a=array([1,2,3,4,5])
b=array([6,7,8,9,10])
c=array([i for i in a + [j for j in b]])
print(c)
But there is no for loop used.
i am absolutely loving it sir. you teach to the point and every minute i spend here feels like i am learning something new.a big thanks for your effort.
Q2.
max = 0
for i in range(len(arr1)):
if(max
its working but can u please explain it
@@Cristiano_Ronaldo_28_17_7 what we are doing here is - we are traversing the list (arr1) element one by one.
In the if condition we are checking that does current element have greater value than max variable have ?
If yes than we will store the value of current element in max variable else continue traversing the list i.e. next element
And at the end we are printing max variable value.
@@Sandythecoder1010 thank you now I got it
Thankyou
You make learning really very easy.It is because of you that I developed interest in learning something new.
Thank You a Lot!!
Don't know whether it's the best answer but as a beginner I feel good somewhat now.
#1)Write a code to add 2 arrays using forloop.
from numpy import *
arr1=[1,2,3,4,5]
arr2=[3,1,8,9,4]
arr=[]
for i in range(len(arr1)):
a= arr1[i] + arr2[i]
arr.append(a)
print(arr)
#2)Write a code to find the maximum value from an array without using in-built fuction
arr=[121,54,78,343,269,313]
temp_max=arr[0]
for i in range(len(arr)):
if arr[i]>temp_max:
temp_max=arr[i]
print(temp_max)
For numpy , append doesnt work
Just use array module instead of numpy here. Append won't work for numpy
The one you made isn't an array btw, an array has to be defined as array([elements]). That's why append is working for you in this code
Great logic for max btw!
#1. add two arrays using for loop
from numpy import *
arr1 = array([1,2,3,4,5])
arr2 = array([12,12,12,2,2])
for i in range(len(arr1)):
sum = arr1[i]+arr2[i]
print(sum)
#2. find maximum value from array without using in-built function
from numpy import *
arr = array([23,12,56,90])
max = arr[0] #suppose value at 0 index is the greatest
for i in range(len(arr)):
#compare
if arr[i]>max: #print(arr[i]) ----- print the values present at a particular index
max = arr[i]
print(max)
#3. add 5 to each element of an array using for loop
from numpy import *
arr = array([15,2,55,4,5])
for i in range(len(arr)):
res = arr[i]+5
print(res)
great work
Kind of late but in solution of 1. you are not checking which arr is greater. if len of arr1 is greater your code will fail. Been 3 years not sure where you are or if you are even doing python lol.
but this code will work in any case:
arr1 = ([1,2,3,4,5])
arr2 = ([1,2,3,4])
if len(arr1)
@@chitranjansingh8432 your assumption is wrong... And we don't need to use this, as the inputs of arr1 and arr2 are given by us... Your code is usable when we take the inputs of arr1 and arr2 from an user....
I didn't get it can u plzz explain this.
Adding 5 in single array set
from numpy import *
arr=array([1,2,3,4,5])
for i in range (5):
print(arr[i]+5)
use break key at the end or else it will print five times
Sir!!!! Python is really awesome language as you are teaching us.I am really get very interested from Python.thank you sir
Your videos are best continue this your channel will grow very fast
from numpy import *
arr1 = array ([8,5,7,8,4])
arr2 = array ([3,6,9,2,5])
For i in range (len(arr1)):
arr3 = arr1 + arr2
break
print (arr3)
1. From numpy import *
Arr1 = array ([1,2,3,4,5])
Arr1 = array ([10,9,8,7,6])
For y in range (0,4):
x=arr1[y] + arr2[y]
print (x)
Naveen,i m getting more confident on python,after seeing your tutorial videos,Thanks much.
Solution 2:
arr=[2,11,4,5,6,12,8]
max=arr[0]
for i in range(1,len(arr)):
if arr[i] >max:
max=arr[i]
print(max)
thanks..
@@anshpatidar5842 👍
I count myself lucky to learn from your tutorial
Thanks sir,
for assignment 2:
arr_a = array([-77, -65,-9,-2,-5])
max_v = arr_a[0]
for i in arr_a:
if max_v < i:
max_v = i
print(max_v)
add 2 arrays using forloop
import array as arr
b = arr.array('i',[1,2,3,4])
c = arr.array('i',[5,6,7,8])
for i in c:
b.append(i)
if len(c) == i:
break
print(b)
finding the max value from array
b = np.array([1,2,3,4])
max = np.array([0])
for k in range(0,len(b)):
if (b[k] > max):
max = b[k]
print(max)
taken time to sort it, but worked :)
solution for 1.
from numpy import *
arr1 = array([2,5,1,7,3])
arr2 = array([1,4,6,2,3])
arr3 =zeros(5,int)
for i in range (5):
arr3[i] =arr1[i]+arr2[i]
print(arr3)
its not working
1)
from array import *
a = array('i',[5, 6, 5, 9, 1])
b = array('i',[8, 2, 3, 4, 7])
c = sorted(a)
d = sorted(b)
e = array('i',[])
for i in range(len(a)):
f = c[i] + d[i]
e.append(f)
print(c)
print(d)
print(e)
2)MAX NUMBER
from numpy import *
a = array([51, 36, 55, 99, 61])
b = sort(a)
print(b[-1])
for pro 1:
from array import *
a = array('i',[1,2,3])
b = array('i',[10,20,30])
c = array('i',[])
for i in range(len(a)):
c.append(a[i] + b [i])
print(c)
Please explain I didn't understand the 1st solution.
Same kaam itna simple ho jana tha bhai tumhary code ne dimag ke dahi kar di
What he did was he created another array and then stored the sum of the other two arrays using the append function in the third one
I'm getting array index out of range
Assignment >>
1)
from numpy import *
arr1= array([1,2,3])
arr2=array ([4,5,6])
for i in range(len(arr1)):
print(arr1[i]+arr2[i])
2) from numpy import *
arr1=array([1,3,6,9,4])
for i in range(len(arr1)-1):
if arr1[i]>arr1[i+1]:
max=arr1[i]
else:
max=arr[i+1]
print(max)
Thanks!!!!
solution 2:
from array import *
arr = array('i',[23,34,5,6])
for i in range(3):
if arr[i]>arr[i+1]:
temp = arr[i]
arr[i]=arr[i+1]
arr[i+1]=temp
print(arr[3])
Could you please shortly explain why you're using 3 in a range? What if I would take the length of an array as an argument? Thanks a lot!
#2. Write a code to find the maximum value:
from numpy import *
arr=([2,4,5,21])
max =0
for i in range(len(arr)):
if arr[i]>max:
max=arr[i]
else:
continue
print(f"maximum value is {max}")
from numpy import *
arr1 =array ([1,2,3,4,5])
arr2 =array ([6,7,8,9,10])
for i in arr1+arr2:
print(i)
I am looking for a job. I am a mechanical guy. Trying for CAE domain, the company I went for the interview has now asked me to learn python and come.
I am really grateful I got this channel.
The good thing is that I am progressing.
from numpy import *
ar1 = array([1, 2, 33, 44, 54, 16, 32])
m=ar1[0]
for i in ar1:
if i>m:
i,m=m,i
else:
continue
print(m)
would you please explain the line 'm=ar1[0]'. I can't understand this line.
from numpy import *
arr1=array([9,2,3,4])
arr=arr1[0]
for i in arr1:
if(i
Code is good. It is working. But it gives minimum value. Since he asked for maximum value u need to change iarr.
prob-2
from array import *
arr = array('i',[1,2,34,56,74,77,89])
sor = sorted(arr)
sor.reverse()
print(sor[0])
but we cannot use any built in function
Sometimes I'm sobbing to understand ur code sir but later I understand easily then I think it is easy to me thank for ur supporting sir to ours for python learning.... 🤝🤝👍👍🙏🙏
After watching your videos, one by one
I feel like I know more than my teachers 😂😂😂
surely
Same here👍
same here
this helped in list type but how to use this method in array
a = [1, 23,67,56, 4]
max_value = 0
for i in a:
if i > max_value:
max_value = i
print (max_value)
That's your dream
sir : ) ) you are the best tutor of python in you tube.
The way you are explaining is fantastic. Strongly believe as you will rock
For 1st:
from numpy import*
a = array([10,20,30,50,20])
b = array([12,2,0,7,5])
for i in a,b:
i = a+b
print(i)
break
hii just now started to learn python , i am following your python series ... the way u r representing everything (content , background text images etc , presentation , clear explanation )in this series is awesome , can u include some assignments or project in between video series .
iit walon ko youtube pe padna par raha hai????🤨🤨🤨
@@hozaifashakeel7758 you tube is a great source of information ....isme tumhe Kya dikkat he ?
Khi na khi se , kabhi na kabhi to pdhna hi pdta he .... I read from other sources also but I found you here only :D
@@ganeshiitr-cse6328 i thought iit is the best anyone can get
arr1 = [1,2,3,4,5,6]
arr2 = [7,8,9,1,2,3]
result = []
for i in range(len(arr1)):
result.append((arr1[i]) + arr2[i])
print('result', result)
Thank you so much Navin for this wonderful sessions.
# Adding 5 to each element of array:
from numpy import *
arr = array([1,2,4,6,5])
#
for i in range(5):
arr[i] = arr[i] + 5
print(arr)
___________________
# Adding two arrays using array module:
from array import *
arr1 = array('i',[1,2,4,6,5])
arr2 = array('i',[2,5,6,4,8])
#
arr3 = array(arr1.typecode,[])
for i in range(5):
x = arr1[i] + arr2[i]
arr3.append(x)
print(arr3)
**Please help to do the same by using "numpy" module.
___________________
# Finding max value:
from numpy import *
#
arr = array([70,10,3,80,8])
#
max = arr[0]
#
for i in range(1,5):
if arr[i] > max:
max = arr[i]
print("Maximum value of array is:",max)
**Please correct me if i am not efficient.
#Thank you sir
#Ans 1:
from numpy import *
arr1 = ([])
arr2 = ([])
n = int(input("Enter the size of the arrays : "))
print("Enter elements of the first array : ")
for i in range(n):
arr1.append(int(input()))
print("Enter elements of the second array : ")
for i in range(n):
arr2.append(int(input()))
arr3 = arr1.copy()
for i in range(len(arr1)):
arr3[i] = arr1[i] + arr2[i]
print(arr3)
#Ans 2:
from array import *
arr = array('i', [2, 1, 3, 5])
for i in range(len(arr)-1):
if arr[i] < arr[i+1]:
max = arr[i+1]
print(max)
why there i sneed for arr33 = arr1.copy() function? Why it is not workinh without blank arr3[]
1st answer wron since ur arr1 and arr2 are list not numpy array. numpy array dont support append method.. only list and normal array support append
from numpy import *
arr1 =array([1,2,3,4])
arr2 =array([5,6,78,3])
b = len(arr1)
for a in range (b):
x = arr1[a]+ arr2[a]
print (x,' ',end='')
Nice solution.
Explanation is good and can understand the demo given with background explanation.... Thanks Navin ....
from numpy import *
arr1 = array([1, 2, 3, 4, 5])
arr2 = array([6, 7, 8, 9, 10])
for a, b in zip(arr1, arr2):
print(a+b)
Zip is inbuilt function
from numpy import *
print("adding 2 arrays using for loop")
ar = array([3,4,5,6,7])
ar2=array([4,5,6,7,8])
ar3=array([])
for i in range(len(ar)):
ar3=ar+ar2
print(ar3)
from array import *
n = int(input("Enter the length of array:"))
a = array("i",[])
for i in range (n):
x = int(input("Enter the element:"))
a.append(x)
l = a[0]
for i in range(n):
if a[i] > l:
l=a[i]
print(l)
I am learning more from u than my cllg
from numpy import *
from numpy import array
arr1 = array([1,2,7,4,9])
max=0
for num in arr1:
if num>max:
max=num
print(max)
What if my numbers are negative?
from array import *
arr = array('i',[88,2,34,56,74,77,89])
sor = sorted(arr)
n = len(sor)
print(sor[n-1])
Q 2)
from numpy import *
arr=array([34,12,14,15,33,22])
max=arr[0]
for i in range(len(arr)):
if max
Finding max value without inbuilt function:
arr1 = array ([9,12,5,41,8,11,31])
z =0
for e in arr1:
if z
Most underrated comment..
I think z=arr1[0] will be more efficient than z=0, because if you take z=0 then finding the max value in an array of negative numbers is impossible
FOR 2ND ASSIGNMENT QUESTION ✌️
from numpy import *
arr=array([11,22,33,44,55])
max=0
for i in arr:
if max
2)
ar = array([3,4,5,6,8])
x=ar[0]
for i in range(0,len(ar)):
if(ar[i]>x):
x=ar[i]
print("The largest elemt in array is",x)
Solution for number 2:
from numpy import *
ar =array([71,18,5,27,9])
ar.sort()
print(ar[len(ar)-1]," is the maximum value")
what about not using built in function?
@@Sandythecoder1010 Check my solution
from numpy import *
print("******Copying an Array**********")
arr1 = array([100,15,19,17,225])
max = 0
for i in range(len(arr1)):
if arr1[i] > max:
max = arr1[i]
else:
pass
print(max)
@@samchaudhry908 Right but you can still improve your code.
@@Sandythecoder1010
arr = array('i', [1, 2, 8, 5, 6])
maxi = 0
for i in range(len(arr)):
if (arr[i] > maxi):
maxi = arr[i]
print(maxi)
@@moizghauri5578 all the items in arr are greater than 0
very good video, teaching style is v good and understandable, I am new to programming and learning quite well, Thankyou
Solution For 2!!!!!!!
from numpy import *
a= array([44,211,12,110,1144])
mx=0
for i in range(4):
if a[i]>a[i+1] and a[i]>mx:
mx=a[i]
elif a[i+1]>mx:
mx=a[i+1]
print('Maximum value is',mx)
i have a better code:
from array import*
arr=array('i',[1,2,3,5,4])
maximum= arr[0]
for i in range(1,5):
if arr[i]>maximum:
maximum=(arr[i])
print(maximum)
solution for problem 2:--->>
from numpy import *
arr = array([1,2,3,4,5])
max = arr[0]
for i in range(5):
if arr[i] > max:
max = arr[i]
print("max is: " , max)
Q:write a code to find the maximum value from an array without using built in function.
Ans: from numpy import *
arr=array([])
n=int(input('enter the size of array:'))
for i in range(n):
x=int(input('enter the value:'))
arr=append(arr,x)
print(arr)
for e in arr:
for z in range(n):
if e>=arr[z]:
pass
else:
break
else:
print(e,'is th greatest number')
from numpy import *
a=array([41,22,39,57,12])
p=a[0]
for e in a:
if e>=p:
p=e
print(p)
Thank you it worked
I would like to shout this at the top of my lungs.
YES, I AM ENJOYING NAVIN'S LESSONS!!!
code:
from numpy import *
arr = array([1,2,3,4,5])
print(arr)
for i in range(len(arr)):
arr[i] = arr[i]+5
print("the new array is ", arr)
M
from numpy import *
arr= array([3,53,5,4,1,52,7,23,1,3])
min = arr[0]
for i in range(0,len(arr)-1):
if arr[i+1] < min :
min = arr[i+1]
print(min)
arr = array([1,2,3,43,4,5])
max = arr[0]
for i in range(len(arr)-1):
if arr[i+1]> max:
max = arr[i+1]
print(max)
from array import *
arr1 = array('i',[1, 2, 3, 9])
arr2 = array('i',[1, 2, 3, 4])
arr3 = array('i',[])
l_arr1 = len(arr1)
l_arr2 = len(arr2)
if l_arr1 == l_arr2 :
for i in range(l_arr1):
arr3.append(arr1[i]+arr2[i])
else:
print("Both array should be same length !")
print("Added new values :\t")
for j in arr3 :
print(j,"\t",end="")
arr = array([12,2,43,56,78])
p = 0
for i in range(len(arr)):
if p
If all are negative in array, then it will print maximum value 0, while It is not part of array
#Addition
from numpy import *
arr = array([10,200,30])
arr1 = array([40,300,20])
arr2 = zeros (3,int)
for x in range(len(arr)):
arr2[x] = arr[x]+arr1[x]
print(arr2)
#2
from array import *
a = ([1,3,5,2])
a.sort()
print(a[-1])
print(a)
not use inbuilt funcition
you have not created an array
Wow guru jee y are one of the best
You have deep knowledge in this field I hope this
Quiz: 1-
from numpy import *
arr1 = array([1,2,3,4,5])
arr2 = array([5,6,7,8,9])
arr3 = array([])
for i in range(5):
arr1[i]= arr1[i]+arr2[i]
arr3=arr1
print(arr3)
Bro where you have wriiten Arr1[i]
Can't we write arr3[I] there
Mera mtlb direct arr3[I] q ni likhe ho...baad me Arr1 ko arr3 me copy ni Krna pdta...
from array import *
a=array('i',[1,2,3,4,5])
b=array('i',[5,4,3,2,1])
c=array('i',[])
for i in range(0,5):
c.append(a[i]+b[i])
print(c)
arr=array([1,2,3,4,5])
for i in range(1):
print(arr+5)
from array import *
arr =array('i',[1,2,5,3,7])
maxValue =0
for i in range(len(arr)):
if arr[i]>maxValue:
maxValue =arr[i]
print(maxValue)
output:7
bahut hard
from numpy import *
arr = array([5,6,7,8,2,1],int)
for arr in arr:
print(arr+5)
1.code 1
from numpy import *
arr1 = array([3,78,9,56])
arr2 = array([35,8,79,36])
arr3 = ones(4,int)
k=0
for k in range(4):
for a in arr1:
for b in arr2:
arr3[k]=arr1[k]+arr2[k]
print(arr3)
2.code 2
from numpy import *
arr = array([3,90,9,56])
max=arr[0]
for i in range(4):
if max
Wow sir I love your teaching method you explain everything clearly and I like it. I've learned many things from you
from numpy import *
val = array([45,25,16,10,2,798,-78,-1])
min = max = val[0]
for i in val:
if i > max:
max = i
elif i < min:
min = i
print("Maximum value of the array element is :\t",max)
print("Minimum value of the array element is :\t",min)
arr= array([1,10,5,6])
Max=0
for i in arr:
if i>max:
Max=i
print(max)
1st Solution:
from numpy import *
arr1 = array([5,10,7,8,4])
arr2 = array([3,5,9,14,17])
for i in range(len(arr1)):
arr3 = arr1 + arr2
print(arr3)
//Adding 5 to each element of an array//
from numpy import *
arr = array([2,4,3,1,5])
for i in range(len(arr)):
arr[i] += 5
print(arr)
Adding 5 to each number
from numpy import *
arr = array([2, 3,4,5])
print(arr[0:]+5)
Thank u so much sir the way u teach is really awesome....I understand much better here than my clg
2nd assignment question
from numpy import *
arr1=array([12,23,34,45,56,67])
arr2=array([21,32,43,54,65,76])
arr3=array ((n for n in arr1)+(k for k in arr2))
print(c)
sir good morning
i am enjoying this series a lot love u sir...
1.
# import the array module
import array as arr
# create two arrays with some values
arr1 = arr.array('i', [2, 4, 6, 8, 10])
arr2 = arr.array('i', [1, 3, 5, 7, 9])
# create an empty array to store the sum
arr_sum = arr.array('i')
# get the length of the arrays
n = len(arr1)
# loop through the arrays
for i in range(n):
# add the elements at the same index
s = arr1[i] + arr2[i]
# append the sum to the new array
arr_sum.append(s)
2.
import array as arr
# create an array with some values
a = arr.array('i', [10, 20, 30, 40, 50])
# initialize the max value to the first element
max_value = a[0]
# loop through the array
for i in range(1, len(a)):
# compare each element with the current max value
if a[i] > max_value:
# update the max value if a larger element is found
max_value = a[i]
# print the max value
print(max_value) # Output: 50
sol 2
finding maximum value
arr = array('i',[1,2,30,2,5,4])
x=0
for i in arr:
for e in arr:
if e>x:
x=e
print(x)
Good, but only works for positive numbers
2:
import numpy as np
arr = np.array([1,6,1000,2,300])
a = arr[0]
for i in range(len(arr)):
if a
for question number 2:
from numpy import *
arr = array ([5,7,2,8,1])
arr1= append(arr.copy(),0)
for i in range(0,len(arr)):
for j in range(i+1,len(arr1)):
if arr[i] > arr1[j]:
a= arr[i]
else:
b=arr1[j]
if a>b:
print(a, 'is the greatest value')
else:
print(b, 'is the greatest value')
2)
from numpy import *
arr1 = array([175, 973, 181, 873, 1056, 157, 354, 279, 710, 199])
numMax = 0
for i in arr1:
if i > numMax:
numMax = i
print(numMax)
Hi sir.. loved all ur videos.. keep posting. Previously learned java from u then SQL and now python.. thanks :)
I did not do the manual way of loop instead i used the dynamic way you have shown in the earlier videos
from array import *
arr = array('i',[1,2,3,4,5])
copyarr = array(arr.typecode, (a+5 for a in arr))
print(copyarr)
from array import *
n=int(input('Enter Length Of Array'))
arr=array('i',[])
for i in range(n):
x=int(input('Enter Your Value'))
arr.append(x)
print(arr)
print(max(arr))
from numpy import *
ar = array([6,8,40,6,45])
for i in range(len(ar)):
for a in range(i+1,5):
if ar[i]< ar[a]:
break
else:
y = ar[i]
break
print(y)
sum of two arrays having diff no of elements:
from numpy import *
a1=array([2,5,8,6,4,9,7])
a2=array([6,8,3,7,2,5])
l1=len(a1)
l2=len(a2)
if(l1max):
max=a1[i]
print(max)
1st answer:
from numpy import *
arr = array([1,2,3,4,])
size = len(arr)
max_val = arr[0]
for i in range(1,size):
if max_val < arr[i] :
max_val = arr[i]
print(max_val)
thank you :)