This file contains hidden or 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
list_a, list_b = zip(*zipped_object) | |
>> list_a | |
(1, 2, 3, 4, 5) | |
>> list_b | |
('a', 'b', 'c', 'd', 'e') |
This file contains hidden or 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
np.random.seed(25) #setting a seed | |
print(np.random.rand(3)) | |
>> [0.87012414 0.58227693 0.27883894] | |
np.random.seed(25) | |
print(np.random.rand(3)) | |
>> [0.87012414 0.58227693 0.27883894] | |
print(np.random.rand(3)) | |
>> [0.52071879 0.32605113 0.69918624] |
This file contains hidden or 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
a = np.arange(4) | |
print(a,'\n') | |
>> [0 1 2 3] | |
b = np.reshape(a,(2,2)) | |
print(b, '\n') | |
>> [[0 1] | |
[2 3]] | |
c = b.reshape(4) |
This file contains hidden or 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
a = np.arange(4).reshape((2,2)) | |
for i in np.nditer(a): | |
print(i) | |
>> 0 | |
1 | |
2 | |
3 |
This file contains hidden or 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
a = np.arange(2,10,2) | |
print(a) | |
>> [2 4 6 8] | |
print(a>5) | |
>> [False False True True] | |
b = np.flatnonzero(a>1) | |
print(b) | |
>> [2 3] |
This file contains hidden or 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
ages = np.random.randint(10,50,10) | |
heights = np.random.randint(120,210,10) | |
>> ages | |
[24 22 13 26 31 20 29 32 34 19] | |
>> heights | |
[146 141 166 191 169 203 149 135 170 152] | |
sorter = np.argsort(ages) |
This file contains hidden or 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
a = np.random.randint(5,10,5) | |
>> a | |
[6 5 8 8 7] | |
np.add.at(a,np.flatnonzero(a>8),2) #flatnonzero returns the indices where values are >8 | |
>> a | |
[6 5 10 10 9] | |
np.maximum.at(a,[0,1,2],60) #checks the max value | |
>> a |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 pandas as pd | |
time_format = '%Y-%m-%d %H%M%S' | |
date = ['2015-01-01 091234','2015-01-01 091234'] | |
time_format_date = pd.to_datetime(date,format=time_format) | |
print(time_format_date) | |
>> DatetimeIndex(['2015-01-01 09:12:34', '2015-01-01 09:12:34'], dtype='datetime64[ns]', freq=None) |