Program to copy data from a given array to another array

In this python numpy program, we will copy data from a given array to another array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Create an empty array of the same size as the given array.
  4. Use for loop to iterate over the given array and add all elements to the empty array.
  5. Print both arrays to see the output.
				
					import numpy as np
x = np.array([[6, 5, 7],[10, 9, 1],[7, 8, 2]])
y = [None] * len(x)
print(y)

for i in range(0,len(x)):
    y[i] = x[i]
    
print("Elements of original array: ");    
for i in range(0, len(x)):    
    print(x[i])    
     
print("Elements of new array: ");    
for i in range(0, len(y)):    
     print(y[i])  
				
			

Output :

				
					[None, None, None]
Elements of original array: 
[6 5 7]
[10  9  1]
[7 8 2]
Elements of new array: 
[6 5 7]
[10  9  1]
[7 8 2]
				
			

calculate the sum of all columns of an array

Leave a Comment