old_contents: #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  Created on Mon Nov 28 14:01:47 2016
  
  @author: haizhu
  """
  
  import numpy as np
  
  def perispecdiff(f):
      # regardless of input, the output is a column array
      N = f.size
      f = f.reshape((N,1))
      if np.mod(N,2) == 0:
          vec = np.append(np.append(np.array([0]),1j*np.arange(1,N/2),axis=0),
                          np.append(np.array([0]),1j*np.arange(-N/2+1,0),axis=0),axis=0)[np.newaxis]
          g = np.fft.ifft( np.fft.fft(f.T)*vec ).T
      else:
          vec = np.append(np.append(np.array([0]),1j*np.arange(1,(N+1)/2),axis=0),
                          1j*np.arange((1-N)/2,0),axis=0)[np.newaxis]
          g = np.fft.ifft( np.fft.fft(f.T)*vec ).T
      
      return g
new_contents: #!/usr/bin/env python3
  """
  @author: Bobbie Wu, 12/8/16
  """
  
  import numpy as np
  from numpy.fft import fft, ifft
  
  def perispecdiff(f):
      # regardless of input, the output is a column array
      N = f.size
      f = f.reshape((N,1))
      if np.mod(N,2) == 0:
          vec = np.c_[0, [1j*np.arange(1,N/2)], 0, [1j*np.arange(-N/2+1,0)]].reshape(N,1)
      else:
          vec = np.c_[0, [1j*np.arange(1,(N+1)/2)], [1j*np.arange((1-N)/2+1,0)]].reshape(N,1)
      return ifft(fft(f,axis=0) * vec, axis=0)
  
  def test_perispecdiff():
      N = 50
      tj = 2*np.pi/N*np.arange(N).reshape((N,1))
      f = np.sin(3*tj)
      fp = 3*np.cos(3*tj)   # trial periodic function & its deriv
      print(np.linalg.norm(fp - perispecdiff(f)))
  
  if __name__ == '__main__':
      test_perispecdiff()
subject: rewrite periodic spec diff