python

从控制台执行一个py文件

exec(open("d:\\temp\\sample01.py").read())

x[m,n]是通过numpy库引用数组或矩阵中的某一段数据集的一种写法,

  1. X = np.array([[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[16,17],[18,19]])  
  2. print X[:,0]  
  3.    

结果是[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.

# initializing lists

name = [ "Manjeet", "Nikhil", "Shambhavi", "Astha" ]

roll_no = [ 4, 1, 3, 2 ]

marks = [ 40, 50, 60, 70 ]

  

# using zip() to map values

mapped = zip(name, roll_no, marks)

  

# converting values to print as set

mapped = set(mapped)

  

# printing resultant values 

print ("The zipped result is : ",end="")

print (mapped)

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.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

novodexx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值