This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CSVからの読みこみ | |
| g = np.genfromtxt("gen.csv",delimiter=",") | |
| print g | |
| # CSV出力 | |
| np.savetxt("saved.csv", c, delimiter=",", fmt="%.2f") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import os, sys, unittest | |
| import math | |
| class Sample(): | |
| def sigmoid(self, v): | |
| return 1.0 / (1 + math.e**(-v)) | |
| class SampleTest(unittest.TestCase): | |
| def setUp(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| list0 = [] | |
| list1 = [1,2,3] | |
| if list0: | |
| print 'list0' #長さ0なのでFalse扱いで実行されない | |
| if list1: | |
| print 'list1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def bubble_sort(arr): | |
| n = len(arr) | |
| total_swap = 0 | |
| for i in xrange(n): | |
| numberOfSwaps = 0 | |
| for j in xrange(n - 1): | |
| if arr[j] > arr[j + 1]: | |
| arr[j], arr[j + 1] = arr[j + 1], arr[j] | |
| numberOfSwaps += 1 | |
| total_swap += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| A = set([1,2,3]) | |
| B = set([2,3,4]) | |
| A ^ B | |
| => set([1, 4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test(): | |
| A = [5,2,4,6,1,3] | |
| print(A) | |
| for i in range(1, len(A)): | |
| print('A', A) | |
| v = A[i] | |
| # search insert position | |
| j = i - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def call(): | |
| print('call') | |
| for i in range(0, N): | |
| for j in range(i+1, N): | |
| call() | |
| # Q. callは何回呼ばれるか? | |
| # A. N-1, N-2, ..., 1の和なので、(N-1) * N / 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = 5 | |
| b = a / 2 | |
| print(b) #=> 2.5 | |
| c = a >> 1 | |
| print(c) #=> 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print(100 / 3) # 33.333333 | |
| print(100 // 3) # 33 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| l = ['a', 'b', 'c'] | |
| for i, c in enumerate(l, start=1): | |
| print(i, c) |