Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 14, 2019 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/ff5a4c44918eb1e3bcc7ab983cfdbfec to your computer and use it in GitHub Desktop.
Save Robofied/ff5a4c44918eb1e3bcc7ab983cfdbfec to your computer and use it in GitHub Desktop.
Numpy
## Creating a int8 type of array.
z = np.int8([-12,2,3])
## Printing the array.
print(z)
#[Output]:
#array([-12, 2, 3], dtype=int8)
## Creating an array with datatype -> uint.
## With negative values as well to check what will happen.
a = np.uint([-12,2,3])
## Printing to check values, so here -12 is converted to some other number in the range of that data type.
## Here unit == unit32 so a big no. is coming in replacement.
print(a)
#[Output]:
#array([4294967284, 2, 3], dtype=uint32)
## If you will check here with unit8 then, it is returning a small no not as large as previous one.
## becasue uint8 has range (0 to255)
b = np.uint8([-12,2,3])
print(b)
#[Output]:
#array([244, 2, 3], dtype=uint8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment