What do you want to save?
Add Code snippet
New code examples
-
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 -
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 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 -
Python 2022-02-02 06:06:04
matplotlib animation
import matplotlib.pyplot as plt from matplotlib import cm import numpy as np from celluloid import Camera numpoints = 10 points = np.random.random((2, numpoints)) colors = cm.rainbow(np.linspace(0, 1, numpoints)) camera = Camera(plt.figure()) for _ in ra... Add solution -
Other 2022-01-30 22:40:32
tqdm update with apply_async in multiprocessing
import time import random from multiprocessing import Pool from tqdm import tqdm def myfunc(a): time.sleep(random.random()) return a ** 2 pool = Pool(2) ''' for _ in tqdm(pool.imap_unordered(myfunc, range(100)), total=100): pass ''' pbar = t... Add solution
Best helpers
Ranking is empty