Numpy questions

By | June 28, 2019

Numpy Interview questions?


  1. How to create a numpy array from existing array?
    Using asarray() we can create ndarray from existing data.

    
                    
                    aList=[2,3,4,5]
                    nArray=np.asarray(aList)
                    print(type(nArray))
                    Output:  class 'numpy.ndarray'
                    
                
    
  2. How to create numpy array in specific range?
    Using arange(start,stop,step) we can create ndarray from existing data.

    
                    
                    nArray=np.arange(0,10,5)
                    print(nArray)
                    Output:  [0 5]
                
                
    
  3. How to create list of equally spaced values in specific range?
    Using linspace(start,stop,numberofvalues) we can create ndarray from existing data.

    
                    
                    nArray=np.linspace(0,5,2)
                    print(nArray)
                    Output:  [ 0.   2.5  5.   7.5 10. ]
                    
                
    
  4. How to iterate over numpy array?
    Using nditer object we can achieve this.

    
                    
                    nArray=[1,4,5,6,7]
                    for i in np.nditer(nArray):  
                        print(x,end=' ')  
                    
                
    
  5. How to iterate over numpy array?
    Using nditer object we can achieve this.

    
                    
                    nArray=[1,4,5,6,7]
                    for i in np.nditer(nArray):  
                        print(x,end=' ')  
                    
                
    
  6. What are the bitwise operators in Numpy?
    Below are bitwise operators available in Numpy:

    1. bitwise_and Eg:np.bitwise_and(a,b))
    2. bitwise_or
    3. invert
    4. left_shift
    5. right_shift
  7. How to concatenate strings in numpy?
    Using char.add()

    
                    
                    newStr=np.char.add(['Learn'],['Mode On'])
                    print(newStr)
                    
                
    

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.