#30 Python Tutorial for Beginners | Copying an Array in Python

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

For More Queries WhatsApp or Call on : +919008963671

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.

Subscribe to our other channel:
Telusko Hindi :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

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 🙂

fazlurrehmanejazahmad
Автор

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

amitmiskin
Автор

Not all superheroes wear capes, Some teach Python for free...

manojgokhale
Автор

Waoh Sir Navin, who is like me in this am humbled to say I got 100% in this

danielkamau
Автор

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.

OgabekToshniyozov-klzs
Автор

finally I got deep and shallow copy from your videos....before I searched on web n didn't get ….thank you

farnaazkhan
Автор

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")

entertainmentcenter
Автор

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}')

just_a_living_being
Автор

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

ashish
Автор

#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))

wxtqojx
Автор

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

shubhamkadam
Автор

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)

bisrata.
Автор

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.

sreecharan
Автор

from array import *
arr = array('i', [1, 2, 3, 4, 5])
arr1 = array('i', [])


for i in range(len(arr)):
arr1.append(arr[i]+5)
print(arr1)

abhishek-kapoor
Автор

You make learning really very easy.It is because of you that I developed interest in learning something new.
Thank You a Lot!!

shraddhadhawan
Автор

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)

rithishreddy
Автор

#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)

chughprabhkirat
Автор

Your videos are best continue this your channel will grow very fast

ishansaha
Автор

Sir!!!! Python is really awesome language as you are teaching us.I am really get very interested from Python.thank you sir

snehajitchandra
Автор

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)

chanduv