Created
February 15, 2019 12:38
-
-
Save Robofied/efc9758f7b64b79b6585a92896dd8a7e to your computer and use it in GitHub Desktop.
Numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
a = np.arange(6) | |
print(a) | |
#[Output]: | |
#[0 1 2 3 4 5] | |
## 1. Reshaping | |
a.reshape(2,3) | |
#[Output]: | |
#array([[0, 1, 2], | |
# [3, 4, 5]]) | |
## 2. Flattening the array | |
a.ravel() | |
#[Output]: | |
#array([0, 1, 2, 3, 4, 5]) | |
## 3.numpy.ndarray.flat | |
x = np.arange(1, 7).reshape(2, 3) | |
print(x) | |
#[Output]: | |
#array([[1, 2, 3], | |
# [4, 5, 6]]) | |
print(x.flat[3]) | |
#[Output]: | |
#4 | |
print(x.T) | |
#[Output]: | |
#[[1 4] | |
# [2 5] | |
# [3 6]] | |
print(x.T.flat[3]) | |
#[Output]: | |
#5 | |
## 4.Flatten | |
a = np.array([[1,2], [3,4]]) | |
a.flatten() | |
#[Output]: | |
#array([1, 2, 3, 4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment