Skip to content

Instantly share code, notes, and snippets.

View belltailjp's full-sized avatar

Daichi SUZUO belltailjp

View GitHub Profile
@belltailjp
belltailjp / column-wise.py
Last active August 29, 2015 14:20
Enforce 1st row to be smaller than the 2nd
# Construct 2-row ndarray
>>> a = numpy.random.randint(0, 100, (2, 10))
>>> a
array([[95, 31, 25, 68, 88, 25, 71, 55, 16, 14],
[57, 59, 38, 30, 78, 92, 30, 47, 89, 41]])
# Extract columns whose 1st row is larger than the 2nd.
>>> a[:, a[1] < a[0]]
array([[95, 68, 88, 71, 55],
[57, 30, 78, 30, 47]])
@belltailjp
belltailjp / row-wise.py
Created May 5, 2015 12:55
Enforce 1st column to be smaller than the 2nd
# Construct 2-column ndarray
>>> a = numpy.random.randint(0, 100, (10, 2))
>>> a
array([[29, 1],
[33, 36],
[79, 32],
[72, 52],
[30, 9],
[33, 85],
[72, 29],
@belltailjp
belltailjp / benchmark.py
Last active August 29, 2015 14:20
Benchmark of enforcing 1st row/col to be smaller than the second.
import numpy
from benchmarker import Benchmarker
N = 10 ** 8
with Benchmarker(1000) as bench:
@bench('col-proposed')
def _(bm):
a = numpy.random.randint(0, 100, (2, N))
@belltailjp
belltailjp / gist:a9538aaf3221f754e5bf
Last active August 29, 2015 14:21
Inter-conversion between numpy ndimage and PySide QImage
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy
import skimage.io
from PySide.QtGui import *
skimg = skimage.io.imread('imgfile.jpg')
# convert to QImage (skimg can be grayscale or rgb)
@belltailjp
belltailjp / simulation.cpp
Created December 7, 2012 16:38
simulation experiment program for KAZE local feature
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <boost/random.hpp>
#include <boost/format.hpp>
#include "KAZE.h"
#include "config.h"
#include "utils.h"
@belltailjp
belltailjp / demo.cpp
Created December 7, 2012 18:54
demonstration program for kaze local feature
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <boost/random.hpp>
#include <boost/format.hpp>
#include "KAZE.h"
#include "config.h"
#include "utils.h"
#include <glog/logging.h>
void func()
{
throw;
}
int main(int argc, char *argv[])
{
//google glogの初期化
@belltailjp
belltailjp / plain_omikuji.cpp
Created February 6, 2013 13:45
一様乱数だけあるときのおみくじプログラム
#include <iostream>
#include <random>
int main()
{
std::vector<int> prob = {1, 9, 25, 25, 30, 9, 1};
const std::string str[] = {"大吉", "中吉", "小吉", "吉末", "吉", "凶", "大凶"};
std::mt19937 rng;
//出現確率を累積に変換
@belltailjp
belltailjp / discrete_distribution_omikuji.cpp
Created February 6, 2013 13:47
C++11のstd::discrete_distributionを使ったときのおみくじプログラム
#include <iostream>
#include <random>
int main()
{
std::vector<int> prob = {1, 9, 25, 25, 30, 9, 1};
const std::string str[] = {"大吉", "中吉", "小吉", "吉末", "吉", "凶", "大凶"};
std::mt19937 rng;
std::discrete_distribution<int> dst(prob.begin(), prob.end());
@belltailjp
belltailjp / nagoya.json
Last active December 14, 2015 13:15
Example of Livedoor weather API call (Nagoya-city)
% curl "http://weather.livedoor.com/forecast/webservice/json/v1?city=230010" | jq '.'
{
"pinpointLocations": [
{
"link": "http://weather.livedoor.com/area/forecast/2310000",
"name": "名古屋市"
},
{
"link": "http://weather.livedoor.com/area/forecast/2320200",
"name": "岡崎市"