Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Numpy
## Importing numpy library for creating numpy
import numpy as np
## Creating a 1-D array
a = np.array([0,2,1])
print(a)
#[Output]:
#array([0, 2, 1])
## assigning array "a" to array "b"
## This is simple assignment neither view nor copy
b = a
## Checking the value in b
print(b)
#[Output]:
#[0 2 1]
## Checking the id's of b and a
## Both are having same id'd in simple assignment.
print(id(b))
print(id(a))
#[Output]:
#2090539997104
#2090539997104
##See changes if value in any array is updated
##Changing the values in b
b[0] = 3
print(b)
#[Output]:
#[3 2 1]
## Checking if changes is also reflected in a or not.
print(a)
#[Output]:
#[3 2 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.