Skip to content

Instantly share code, notes, and snippets.

View tnarihi's full-sized avatar

Takuya Narihira tnarihi

  • Sony
  • Tokyo, Japan
View GitHub Profile
# -*- coding: utf-8 -*-
import numpy as np
import pylab as pl
__author__ = 'Takuya Nairihira'
def compute_belonging(x, c):
dist_NxK = (x**2).sum(axis=1)[:,np.newaxis] - 2. * np.dot(x, c.T) + (c**2).sum(axis=1)[np.newaxis]
return dist_NxK.argmin(axis=1)
@tnarihi
tnarihi / numpy_tutorial.ipynb
Created March 4, 2014 13:07
日本語によるNumpyのチュートリアル的なもの。IPythonノートブックビューアで見てください。<http://nbviewer.ipython.org/gist/tnarihi/9346213>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"metadata": {
"name": "",
"signature": "sha256:85b09af85413fd379d6f77fe2b2d33945a781e80b345de143d1581b69f4d6298"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tnarihi
tnarihi / parse_libsvm_input.cpp
Last active August 29, 2015 14:11
An example of parsing LIBSVM input format with Boost library
/*
* No Copyright
*/
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream> // NOLINT(readability/streams)
#include <fstream> // NOLINT(readability/streams)
#include <string>
@tnarihi
tnarihi / additional_sbp.sublime-keymap
Last active August 29, 2015 14:11
My personal additional settings for sublemacspro. Copy to my user key-bindings.
[
{ "keys": ["ctrl+x", "["], "command": "move_to", "args": {"to": "bof", "extend": false} },
{ "keys": ["ctrl+x", "]"], "command": "move_to", "args": {"to": "eof", "extend": false} },
{ "keys": ["ctrl+shift+2"], "command": "sbp_set_mark" },
{ "keys": ["ctrl+[", "w"], "command": "sbp_kill_ring_save" },
{ "keys": ["ctrl+[", "b"], "command": "move", "args": {"by": "subwords", "forward": false} },
{ "keys": ["ctrl+[", "f"], "command": "move", "args": {"by": "subword_ends", "forward": true} },
{ "keys": ["ctrl+[", "d"], "command": "sbp_delete_word", "args": { "forward": true } },
{ "keys": ["ctrl+[", "backspace"], "command": "sbp_delete_word", "args": { "forward": false } },
{ "keys": ["ctrl+x", "ctrl+w"], "command": "prompt_save_as" },
@tnarihi
tnarihi / .screenrc
Created December 23, 2014 22:39
My GNU Screen setting
# Filename: $HOME/.screenrc
# Purpose: Setup file for program "(GNU) screen"
# Latest change: Mon Jan 26 10:51:50 CET 2004
# Author: Michael Prokop / <online@michael-prokop.at> / www.michael-prokop.at
# ===============================================================
#
# ===============================================================
# SEE ALSO:
# ===============================================================
# SCREEN Pages:
@tnarihi
tnarihi / README.md
Last active August 29, 2015 14:16
APIs for image transformation and comparisons: OpenCV2 vs Scikit-Image. http://nbviewer.ipython.org/gist/tnarihi/9b860f9f163b66bff8cd

Examples of Python OpenCV2 and Scikit.Image and their comparisons

See the iPython notebook link. In this notebook, you can see various image maniputaion examples using both Python extension of OpenCV2 and Scikit.Image.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tnarihi
tnarihi / README.md
Last active February 27, 2020 16:31
Behaviors of Python threading, multiprocessing and futures.

Behaviors of Python threading, multiprocessing and concurrent.futures

I saw the behaviors as follows:

  1. threading.Thread and multiprocessing.Process do not raise to the main thread.
  2. multiprocessing.Pool and multiprocessing.pool.ThreadPool (this is not documented at all) leave zombie threads.

The results show that concurrent.futures is the best choice for threading and multiprocessing in Python!

I did this experiment on Python 2.7.9, and Python 2.x does not have concurrent.futures, so I installed it by pip command pip install futures.