Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to do downsampling in python

import xarray as xr
import numpy as np
import matplotlib.pyplot as plt

fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15,5))

# Create a 10x10 array of random numbers
a = xr.DataArray(np.random.rand(10,10)*100, dims=['x', 'y'])

# "Downscale" the array, mean of blocks of size (2x2)
b = a.coarsen(x=2, y=2).mean()

# "Downscale" the array, mean of blocks of size (5x5)
c = a.coarsen(x=5, y=5).mean()

# Plot and cosmetics
a.plot(ax=ax1)
ax1.set_title("Full Data")

b.plot(ax=ax2)
ax2.set_title("mean of (2x2) boxes")

c.plot(ax=ax3)
ax3.set_title("mean of (5x5) boxes")
Comment

python downsampling

df_ham_downsampled = df_ham.sample(df_spam.shape[0])
Comment

PREVIOUS NEXT
Code Example
Python :: Convert a list of dictionary into a feature vector 
Python :: how to read xlsx file from one directory above python 
Python :: how to make a password square multicolor square spiral python 
Python :: list all subdirectories up to a level 
Python :: access kwargs in template django 
Python :: pandas print nonzero in series 
Python :: priting matrix using np truncating the output 
Python :: pytorch rolling window 
Python :: rename duplicates in list python 
Python :: mechanize python #6 
Python :: finda argument index 
Python :: convert integer to string python 
Python :: pandas query return column 
Python :: python sys replace text 
Python :: compute difference in dates after groupby 
Python :: close window tkiinter 
Python :: plotly dcc.interval bar graph with time 
Python :: Doubleclick .py Prep 
Python :: xgb plot importance 
Python :: Specifying your data type 
Python :: asterisk triangle print 
Python :: PHP echo multi lines Using Heredoc variable 
Python :: pyqt global hotkey 
Python :: meter replacement application 
Python :: python create empty list with size 10 
Python :: python typing optional argument 
Python :: Python NumPy atleast_2d Function Example when inputs are in high dimension 
Python :: python access to vraiable in another classe 
Python :: Python NumPy vstack Function Example with 1d array 
Python :: pymel layout 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =