Skip to content

Instantly share code, notes, and snippets.

View vinaykudari's full-sized avatar
💭
lets talk code

Vinay vinaykudari

💭
lets talk code
View GitHub Profile
a = set({3,1,2,3})
print(type(a))
>> <class 'set'>
print(a) #Order and Repetition dosent matter in sets
>> {1, 2, 3}
@vinaykudari
vinaykudari / coin_stimulation.py
Created July 29, 2018 15:49
coin_stimulation
def generate_counts(coin_flips=1000, n=1000):
x = 2*(np.random.random((coin_flips, n)) > 0.5) - 1 #generates a 1000x1000 matrix, 1 for heads -1 for tails
s = x.sum(axis=0) #summing row wise, 1000 coin flips for 1000 times together
return s
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.
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)
@vinaykudari
vinaykudari / pd_melting.ipynb
Last active July 26, 2018 16:10
Melting Data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vinaykudari
vinaykudari / importing_data.ipynb
Last active July 25, 2018 22:59
Importing Data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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)
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]