Skip to content

Instantly share code, notes, and snippets.

View ugo-nama-kun's full-sized avatar
🧠
@CogDevRobo

naoto yoshida ugo-nama-kun

🧠
@CogDevRobo
View GitHub Profile
@ugo-nama-kun
ugo-nama-kun / online_plot_matplotlib.py
Last active June 30, 2023 06:00
Online Plotting with Matplotlib
import matplotlib.pyplot as plt
import numpy as np
from collections import deque
plt.figure()
ax = plt.subplot(1,1,1)
plt.ylim([-1.1, 1.1])
plt.xlim([0, 50])
@ugo-nama-kun
ugo-nama-kun / qtoe_etoq.py
Last active May 29, 2021 10:50
Quarternion to Euler & Euler to Quarternion
# Reference: https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
# Quaternion to Euler
def qtoeuler(q):
""" quaternion to Euler angle
:param q: quaternion
:return:
"""
from datetime import datetime
s = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
print(s)
"""
You'll get something like.... 🍺
'2021-06-08-15-35-32'
"""
import numpy as np
from sklearn import datasets
"""
8x8 tiny NIST image handler
NIST dataset: https://scikit-learn.org/stable/datasets/toy_dataset.html#digits-dataset
If you chose NistHandle(flat=True), you'll get 64-dim vector instead of 8x8 numpy array.
@ugo-nama-kun
ugo-nama-kun / get_logger.py
Last active April 25, 2022 04:39
Logger の取り方
import os
from datetime import datetime
import logging.config
from logging import StreamHandler, FileHandler, Formatter
from logging import INFO, DEBUG, NOTSET
def get_new_logger(name, file_path="./log"):
# ストリームハンドラの設定
@ugo-nama-kun
ugo-nama-kun / plot_settings.py
Last active January 12, 2022 03:22
よくある matplotlib で plot してそれを保存する方法:heatmap/300 dpi/png
import seaborn as sns
import matplotlib.pyplot as plt
# load data
x_ticks = np.linspace(0, 1, 10)
y_ticks = np.linspace(0, 1, 10)
# ちなみに save は np.save("data_matrix.npy", data_matrix) みたいなかんじで
data_matrix = np.load("data_matrix.npy")
@ugo-nama-kun
ugo-nama-kun / random_seeding.py
Last active August 2, 2021 10:50
A summary of seeding in some packages
import random
import functools
import numpy as np
import tensorflow as tf
import torch
import gym
import tianshou as ts
@ugo-nama-kun
ugo-nama-kun / number_print.py
Created August 4, 2021 07:12
python の有効数字
print('{:.3f}'.format(123.456))
# 123.456
print(f"{0.12345678:.3f}")
# 0.123
# Other Examples
print('{:.3e}'.format(123.456))
print('{:.3g}'.format(123.456))
print('{:.3}'.format(123.456))
@ugo-nama-kun
ugo-nama-kun / mujoco-py-marker.py
Last active December 6, 2021 05:55
How to use the marker util of mujoco-py
import numpy as np
import gym
from gym.envs.mujoco import mujoco_env
from mujoco_py.generated import const
from scipy.spatial.transform import Rotation
""" Marker types in const
GEOM_PLANE = 0
@ugo-nama-kun
ugo-nama-kun / centering_plots_in_jupyter.py
Last active August 10, 2021 08:03
Plot figure in the center of jupyter notebook
import numpy as np
from IPython.core.display import HTML
import matplotlib.pyplot as plt
# if you like seaborn:
import seaborn as sns
sns.set()
sns.set_context("talk")
HTML("""