python-numpy最全攻略九-equal, less, greater

  1. numpy.equal()和numpy.not_equal()
# This function checks for string1 == string2 elementwise
import numpy as np
 
# comparing a string elementwise
# using equal() method
a=np.char.equal(geeks,for)
 
print(a)
False
import numpy as np
 
# comparing a string elementwise
# using unequal() method
a=np.char.not_equal(geeks,for)
 
print(a)
True
  1. numpy.greater()
# This function checks whether string1 is greater than string2 or not.
import numpy as np
 
# comparing a string elementwise
# using greater() method
a=np.char.greater(geeks,for)
b=np.char.less(geeks,for)
 
print(a)
print(b)
True
False
  1. numpy.random.randint()
import numpy as geek 
  
# output array 
out_arr = geek.random.randint(low = 0, high = 2, size = 10) 
print ("Output 1D Array filled with random integers : ", out_arr)
Output 1D Array filled with random integers :  [0 1 1 1 1 1 1 1 0 1]
import numpy as geek 
  
  
# output array 
out_arr = geek.random.randint(low = 2, size =(2, 3)) 
print ("Output 2D Array filled with random integers : ", out_arr)
Output 2D Array filled with random integers :  [[1 0 0]
 [1 1 0]]
import numpy as geek 
  
# output array 
out_arr = geek.random.randint(2, 10, (2, 3, 4)) 
print ("Output 3D Array filled with random integers : ", out_arr)
Output 3D Array filled with random integers :  [[[9 9 5 4]
  [4 6 8 2]
  [9 7 3 7]]

 [[7 4 2 9]
  [9 5 9 9]
  [9 8 7 7]]]
经验分享 程序员 微信小程序 职场和发展