title: Cython specify numpy array of fixed length strings
body: <p>I have a function that I'd like to use Cython with that involves processing large numbers of fixed-length strings. For a standard cython function, I can declare the types of arrays like so:</p>
  
  <pre><code>cpdef double[:] g(double[:] in_arr):
      cdef double[:] out_arr = np.zeros(in_arr.shape, dtype='float64')
  
      cdef i
      for i in range(len(in_arr)):
          out_arr[i] = in_arr[i]
  
      return out_arr
  </code></pre>
  
  <p>This compiles and works as expected when the dtype is something simple like <code>int32</code>, <code>float</code>, <code>double</code>, etc. However, I cannot figure out how to create a typed memoryview of fixed-length strings - i.e. the equivalent of <code>np.dtype('a5')</code>, for example.</p>
  
  <p>If I use this:</p>
  
  <pre><code>cpdef str[:] f(str[:] in_arr):
      # arr should be a numpy array of 5-character strings
      cdef str[:] out_arr = np.zeros(in_arr.shape, dtype='a5')
  
      cdef i
      for i in range(len(in_arr)):
          out_arr[i] = in_arr[i]
  
      return out_arr
  </code></pre>
  
  <p>The function compiles, but this:</p>
  
  <pre><code>in_arr = np.array(['12345', '67890', '22343'], dtype='a5')
  f(in_arr)
  </code></pre>
  
  <p>Throws the following error:</p>
  
  <blockquote>
    <p>---> 16 cpdef str[:] f(str[:] in_arr):
         17     # arr should be a numpy array of 5-character strings
         18     cdef str[:] out_arr = np.zeros(in_arr.shape, dtype='a5')</p>
    
    <p>ValueError: Buffer dtype mismatch, expected 'unicode object' but got a
    string</p>
  </blockquote>
  
  <p>Similarly if I use <code>bytes[:]</code>, it gives the error "Buffer dtype mismatch, expected 'bytes object' but got a string" - and this doesn't even get to the issue with the fact that nowhere am I specifying that these strings have length 6.</p>
  
  <p>Interestingly, I <em>can</em> include fixed-length strings in a structured type as in <a href="https://stackoverflow.com/q/21435378/467366">this question</a>, but I don't think that's the right way to declare the types.</p>