- np.random_sample()
复制代码
1
2
3
4
5
6
7importing numpy import numpy as np # output random value out_val = np.random.random_sample() print ("Output random float value : ", out_val)
复制代码
1
2Output random float value : 0.2450768662139805
复制代码
1
2
3
4
5
6
7import numpy as geek # output array out_arr = geek.random.random_sample(size =(1, 3)) print ("Output 2D Array filled with random floats : ", out_arr)
复制代码
1
2Output 2D Array filled with random floats : [[0.15468058 0.26536462 0.54954387]]
复制代码
1
2import numpy as geek
复制代码
1
2
3
4# output array out_arr = geek.random.random_sample((3, 2, 1)) print ("Output 3D Array filled with random floats : ", out_arr)
复制代码
1
2
3
4
5
6
7
8
9Output 3D Array filled with random floats : [[[0.6380224 ] [0.73029307]] [[0.51149673] [0.3413279 ]] [[0.20853883] [0.61981115]]]
- random.ranf()
复制代码
1
2
3
4
5
6
7
8
9# numpy.random.ranf() is one of the function for doing random sampling in numpy. It returns an array of specified shape # and fills it with random floats in the half-open interval [0.0, 1.0). import numpy as np # output random float value out_val = np.random.ranf() print ("Output random float value : ", out_val)
复制代码
1
2Output random float value : 0.44112568416235265
复制代码
1
2
3
4
5
6
7
8# importing numpy import numpy as np # output array out_arr = np.random.ranf(size =(2, 1)) print ("Output 2D Array filled with random floats : ", out_arr)
复制代码
1
2
3Output 2D Array filled with random floats : [[0.69303583] [0.8020658 ]]
复制代码
1
2
3
4
5
6import numpy as geek # output array out_arr = geek.random.ranf((3, 3, 2)) print ("Output 3D Array filled with random floats : ", out_arr)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13Output 3D Array filled with random floats : [[[0.50709171 0.02493862] [0.51112692 0.8210353 ] [0.98668934 0.20536282]] [[0.0707417 0.38774696] [0.01399582 0.14022261] [0.47580447 0.70451949]] [[0.07844355 0.28663839] [0.84763223 0.98383207] [0.6413255 0.63548128]]] numpy.random.random.randint()
- np.bitwise-function
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31# Python code to demonstrate bitwise-function import numpy as np # construct an array of even and odd numbers even = np.array([0, 2, 4, 6, 8, 16, 32]) odd = np.array([1, 3, 5, 7, 9, 17, 33]) # bitwise_and print('bitwise_and of two arrays: ') print(np.bitwise_and(even, odd)) # bitwise_or print('bitwise_or of two arrays: ') print(np.bitwise_or(even, odd)) # bitwise_xor print('bitwise_xor of two arrays: ') print(np.bitwise_xor(even, odd)) # invert or not print('inversion of even no. array: ') print(np.invert(even)) # left_shift print('left_shift of even no. array: ') print(np.left_shift(even, 1)) # right_shift print('right_shift of even no. array: ') print(np.right_shift(even, 1))
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13bitwise_and of two arrays: [ 0 2 4 6 8 16 32] bitwise_or of two arrays: [ 1 3 5 7 9 17 33] bitwise_xor of two arrays: [1 1 1 1 1 1 1] inversion of even no. array: [ -1 -3 -5 -7 -9 -17 -33] left_shift of even no. array: [ 0 4 8 12 16 32 64] right_shift of even no. array: [ 0 1 2 3 4 8 16]
最后
以上就是怡然豌豆最近收集整理的关于python-numpy最全攻略十-random_sample, ranf, bitwise的全部内容,更多相关python-numpy最全攻略十-random_sample,内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复