numpy.ndarray.copy() in Python
numpy.ndarray.copy() returns a copy of the array.
Syntax : numpy.ndarray.copy(order=’C’)
Parameters:
order : Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.
Code #1:
# Python program explaining # numpy.ndarray.copy() function import numpy as geek x = geek.array([[0, 1, 2, 3], [4, 5, 6, 7]], order ='F') print("x is: \n", x) # copying x to y y = x.copy() print("y is :\n", y) print("\nx is copied to y") |
x is: [[0 1 2 3] [4 5 6 7]] y is : [[0 1 2 3] [4 5 6 7]] x is copied to y
Code #2:
# Python program explaining # numpy.ndarray.copy() function import numpy as geek x = geek.array([[0, 1, ], [2, 3]]) print("x is:\n", x) # copying x to y y = x.copy() # filling x with 1's x.fill(1) print("\n Now x is : \n", x) print("\n y is: \n", y) |
x is: [[0 1] [2 3]] Now x is : [[1 1] [1 1]] y is: [[0 1] [2 3]]
Recommended Posts:
- Python | Merge Python key values to list
- Python | Convert list to Python array
- Reading Python File-Like Objects from C | Python
- Python | Index of Non-Zero elements in Python list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to a Python Script
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- pow() in Python
- Any & All in Python
- set add() in python
- chr() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



