"Numpy"의 두 판 사이의 차이
ph
33번째 줄: | 33번째 줄: | ||
array([[1, 2, 3]])</pre> | array([[1, 2, 3]])</pre> | ||
http://stackoverflow.com/a/17428859/766330 | http://stackoverflow.com/a/17428859/766330 | ||
+ | |||
+ | ==Get a distance matrix== | ||
+ | scipy.spatial.distance.pdist(X, metric='euclidean', p=None, w=None, V=None, VI=None) | ||
+ | X : ndarray | ||
+ | X is m by n matrix, and *rows* are observations. So X is *m* observations. | ||
+ | |||
+ | ==a== |
2017년 5월 8일 (월) 17:21 판
bincount
Count number of occurrences of each value in array of non-negative ints.
numpy.bincount(x, weights=None, minlength=None)
https://docs.scipy.org/doc/numpy/reference/generated/numpy.bincount.html
loadtxt
numpy.loadtxt(fname, dtype=<type 'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0)
https://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html
cf. fromstring
- fromstring쓸 때, sep argument로 아무것도 넘겨주지 않으면 binary취급함에 주의. 탭구분자등은
sep=' '
와 같이 공백만 주어도 된다.
histogram
numpy.histogram(a, bins=10, range=None, normed=False, weights=None, density=None)
>>> import matplotlib.pyplot as plt >>> rng = np.random.RandomState(10) # deterministic random data >>> a = np.hstack((rng.normal(size=1000), ... rng.normal(loc=5, scale=2, size=1000))) >>> plt.hist(a, bins='auto') # plt.hist passes it's arguments to np.histogram >>> plt.title("Histogram with 'auto' bins") >>> plt.show()
https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html
Array to column vector
>>> a = np.array([1, 2, 3]) >>> a array([1, 2, 3]) >>> a[:, np.newaxis] array([[1], [2], [3]]) >>> a[np.newaxis, :] array([[1, 2, 3]])
http://stackoverflow.com/a/17428859/766330
Get a distance matrix
scipy.spatial.distance.pdist(X, metric='euclidean', p=None, w=None, V=None, VI=None) X : ndarray
X is m by n matrix, and *rows* are observations. So X is *m* observations.