What do you want to save?
Add Code snippet
New code examples
-
Python 2022-02-13 16:05:11
connect a mean value to histogram pandas
import numpy as np import matplotlib.pyplot as plt np.random.seed(6789) x = np.random.gamma(4, 0.5, 1000) result = plt.hist(x, bins=20, color='c', edgecolor='k', alpha=0.65) plt.axvline(x.mean(), color='k', linestyle='dashed', linewidth=1) min_ylim, max_... Add solution -
Python 2022-02-13 15:30:05
How to replace both the diagonals of dataframe with 0 in pandas
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(1,100, 100).reshape(10, -1)) out = df.where(df.values != np.diag(df),0,df.where(df.values != np.flipud(df).diagonal(0),0,inplace=True)) Add solution -
C# 2022-02-12 07:15:32
c# only letters
bool result = input.All(Char.IsLetter); bool result = input.All(Char.IsLetterOrDigit); bool result = input.All(c=>Char.IsLetterOrDigit(c) || c=='_'); // Instantiate random number generator. private readonly Random _random = new Random(); // G... Add solution -
Python 2022-02-12 01:10:15
snake water gun game in python
# Snake water gun game in python ''' Snake vs. Water: Snake drinks the water hence wins. Water vs. Gun: The gun will drown in water, hence a point for water Gun vs. Snake: Gun will kill the snake and win. In situations where both players choose the same ... Add solution -
Python 2022-02-11 23:15:26
R sample() funciton in python
import numpy as np np.random.choice(values, size=1000, replace=True, p=probability) # values is the input values that correspond to the weights # size is the number of samples to generate # Replace specifies if it's with or without replacement # p is t... Add solution -
Other 2022-02-11 20:15:02
How to shift non nan values up and put nan values down
np.random.seed(100) df = pd.DataFrame(np.random.randn(5,4)) df.iloc[1,2] = np.NaN df.iloc[0,1] = np.NaN df.iloc[2,1] = np.NaN df.iloc[2,0] = np.NaN print (df) 0 1 2 3 0 -1.749765 NaN 1.153036 -0.252436 1 0.981321 ... Add solution -
Python 2022-02-06 20:00:24
pandas read_csv random rows
import pandas as pd import numpy as np filename = 'hugedatafile.csv' nlinesfile = 10000000 nlinesrandomsample = 10000 lines2skip = np.random.choice(np.arange(1,nlinesfile+1), (nlinesfile-nlinesrandomsample), replace=False) df = pd.read_csv(filename, skip... Add solution -
Python 2022-02-06 13:25:02
keras backend matrix multiplication
import keras.backend as K import numpy as np A = np.random.rand(10,500) B = np.random.rand(500,6000) x = K.variable(value=A) y = K.variable(value=B) z = K.dot(x,y) # Here you need to use K.eval() instead of z.eval() because this uses the backend sessio... Add solution