深度学习编程

1.np.flatnonzero()函数
2. np.random.choice()
3. a.shape 函数
返回大小,行-列排布。

# list没有shape这个属性
>>> a=np.array([[0,1,4],[2,3,8]])
>>> a.shape
(2, 3)
>>> a.shape[1]
3
>>> a.shape[0]
2

4、a.reshape()
5、np.argsort()
6、python 中的统计函数

>>> from collections import Counter
>>> vote=Counter([1,1,2,2,2,3,6,7,7,7])
>>> vote
Counter({2: 3, 7: 3, 1: 2, 3: 1, 6: 1})
>>> vote.most_common()
[(2, 3), (7, 3), (1, 2), (3, 1), (6, 1)]

7、np.split()

>>> a=np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.split(a,5)
[array([0, 1]), array([2, 3]), array([4, 5]), array([6, 7]), array([8, 9])]
>>> np.split(a,10)
[array([0]), array([1]), array([2]), array([3]), array([4]), array([5]), array([6]), array([7]), array([8]), array([9])]
>>> np.split(a,3)
Traceback (most recent call last):
  File "E:\python\lib\site-packages\numpy\lib\shape_base.py", line 843, in split
    len(indices_or_sections)
TypeError: object of type 'int' has no len()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    np.split(a,3)
  File "E:\python\lib\site-packages\numpy\lib\shape_base.py", line 849, in split
    'array split does not result in an equal division')
ValueError: array split does not result in an equal division

8、np.concatenate
9、enumerate

k_choices = [1, 3, 5, 8, 10, 12, 15, 20, 50, 100]
>>> for ik,k in enumerate(k_choices):
	print(ik,k)

	
0 1
1 3
2 5
3 8
4 10
5 12
6 15
7 20
8 50
9 100
>>> for ik in enumerate(k_choices):
	print(ik)

	
(0, 1)
(1, 3)
(2, 5)
(3, 8)
(4, 10)
(5, 12)
(6, 15)
(7, 20)
(8, 50)
(9, 100)

10、lambda表达式
11、random:randrange 从中不大于这个数的大小里随机选择一个数。
注意:默认基准值为1

>>> from random import randrange
>>> ix = tuple([randrange(m) for m in x.shape])
>>> ix
(1, 0)
>>> ix = tuple([randrange(m) for m in x.shape])
>>> ix
(1, 1)
>>> ix = tuple([randrange(m) for m in x.shape])
>>> ix
(0, 2)
>>> x.shape
(2, 3)
>>> [m for m in x.shape]
[2, 3]

12、numpy 索引的一种方式

1>>>x=np.array([[1,2,3],[5,6,2]])
>>> x[(1,2)]
2
>>> x[[1,2]]
Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    x[[1,2]]
IndexError: index 2 is out of bounds for axis 0 with size 2
2>>> a=np.array([[1,2,3],[4,5,6]])
>>> a[range(2),1]
array([2, 5])
>>> a
array([[1, 2, 3],
       [4, 5, 6]])
>>> a[1,range(2)]
array([4, 5])
>>> range(2)
range(0, 2)
>>> a[1,list(range(2))]
array([4, 5])
>>> list(range(2))
[0, 1]

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值