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

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

Introduction to Numpy and Array Operations

In this video, the presenter introduces the concept of numpy and array operations. The presenter demonstrates how to create an array using different methods and perform various operations on it.

Adding a Value to Each Element in an Array

  • To add a value to each element in an array, use the operation array + value.
  • This is called vectorized operation.

Adding Two Arrays

  • To add two arrays, use the operation array1 + array2.
  • The output will be a new array with each element being the sum of corresponding elements from both arrays.

Mathematical Operations on Arrays

Finding Sign, Cosine, Logarithm and Square Root of Elements in an Array

  • Use numpy.sign(array) to find sign values for each element in an array.
  • Use numpy.cos(array) to find cosine values for each element in an array.
  • Use numpy.log(array) to find logarithmic values for each element in an array.
  • Use numpy.sqrt(array) to find square root values for each element in an array.

Finding Sum, Minimum and Maximum Values of Elements in an Array

  • Use numpy.sum(array) to find the sum of all elements in an array.
  • Use numpy.min(array) to find the minimum value among all elements in an array.
  • Use numpy.max(array) to find the maximum value among all elements in an array.

Learning by Doing

In this section, the speaker encourages learners to practice coding and experiment with different functions. The speaker also demonstrates how to concatenate two arrays.

Practice Makes Perfect

  • The more you practice, the more you learn.
  • Experiment with different functions to gain a better understanding of how they work.

Concatenating Arrays

  • To concatenate two arrays, use the concatenate function and pass in both arrays as arguments separated by a comma.
  • Example: np.concatenate((arr1, arr2))

Copying Arrays

In this section, the speaker explains how to copy an array in Python and discusses shallow copy vs deep copy.

Creating a New Array from an Existing One

  • To create a new array from an existing one, simply assign it to a new variable.
  • Example: arr2 = arr1
  • Both variables will point to the same memory address.

Shallow Copy vs Deep Copy

  • Shallow copy copies only the references of objects within the original array. If any object is modified in either array, it will be reflected in both.
  • Deep copy creates a completely independent copy of the original array. Any modifications made to one will not affect the other.
  • Use copy() for shallow copying and deepcopy() for deep copying.

Copying Arrays in Python

In this section, the speaker explains how to copy an array in Python using different methods.

Two Ways to Copy an Array

  • The first way to copy an array is by assigning it directly. For example, ARR2 = ARR1 will create a new reference to the same array.
  • The second way is by using shallow and deep copies. A shallow copy can be created using view(), while a deep copy can be created using copy().

Shallow vs Deep Copies

  • A shallow copy creates a new array that references the original values of the original array. Any changes made to the new array will also affect the original one.
  • A deep copy creates a completely new and independent array with its own set of values. Changes made to the new array will not affect the original one.

Conclusion and Next Steps

In this section, the speaker concludes by summarizing what was covered in this video and previews what will be discussed in the next video.

Recap and Feedback

  • The speaker recaps what was covered in this video: copying arrays in Python using two different methods.
  • The audience is encouraged to leave feedback on whether they enjoyed this video or have any questions for future videos.

Preview of Next Video

  • The speaker previews that the next video will cover their favorite topic: choices in Python.
Video description

Check out our courses: AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS Coupon: TELUSKO10 (10% Discount) Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4 Coupon: TELUSKO10 (10% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 TELUSKO Android App : https://bit.ly/TeluskoApp Discord : https://discord.gg/D8hWe9BqfF 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 :- https://github.com/navinreddy20/Python- Python for Beginners :- http://bit.ly/3JOLQhl Java and Spring Framework For beginners with Spring Boot : - http://bit.ly/3LDMj8D Java Tutorial for Beginners (2023) :- http://bit.ly/3yARVbN Subscribe to our other channel: Navin Reddy : https://www.youtube.com/channel/UCxmk... Telusko Hindi : https://www.youtube.com/channel/UCitz... Donation: PayPal Id : navinreddy20 Patreon : navinreddy20 http://www.telusko.com/contactus

#30 Python Tutorial for Beginners | Copying an Array in Python | YouTube Video Summary | Video Highlight