从控制台执行一个py文件
exec(open("d:\\temp\\sample01.py").read())
x[m,n]是通过numpy库引用数组或矩阵中的某一段数据集的一种写法,
- X = np.array([[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[16,17],[18,19]])
- print X[:,0]
结果是[0,2,4,6...] 里面每个小数组返回第一个元素
[:-1],返回除最后一个的所有元素
It is list indexing, it returns all elements [:]
except the last one -1
.
numpy.linspace使用详解
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
在指定的间隔内返回均匀间隔的数字。
返回num均匀分布的样本,在[start, stop]。
这个区间的端点可以任意的被排除在外。
linspace和arange的区别在于,linspace第三个参数指定了总体的个数,而arange第三个参数是间隔。
有两个反斜杠时,只输出整数,即只输出小数点前的:
numpy.
arange
([start, ]stop, [step, ]dtype=None)
Return evenly spaced values within a given interval.
step默认是1
zip, map the similar index of multiple containers so that they can be used just using as single entity.
|
Output:
The zipped result is : {('Shambhavi', 3, 60), ('Astha', 2, 70),
('Manjeet', 4, 40), ('Nikhil', 1, 50)}
a**b, 表示a的b次方
range(1, 10)是不包含10这个数字的。
reduce(function, iterable[, initializer])
Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
calculates ((((1+2)+3)+4)+5)
. The left argument, x, is the accumulated value and the right argument, y, is the update value from the iterable. If the optional initializer is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. If initializer is not given and iterable contains only one item, the first item is returned.