You should just be able to use np.asarray directly on the memoryview itself, so something like:

np.asarray(my_memview)

should work. For example if your cython source file contains this:

import numpy as np
cimport numpy as np
def test(double[:,:] x):
    print type(x)
    print type(np.asarray(x))

Then after compiling it, you should be able to do the following from the python side:

a = np.random.normal(size=(5,5))
test(a)

Which produces the following output:

<type '_cython_magic_0182fca918bfa3618c3553e51b13e8ba._memoryviewslice'>
<type 'numpy.ndarray'>

Note: I'm using the cythonmagic extension for IPython.

Answer from JoshAdel on Stack Overflow
🌐
Cython
cython.readthedocs.io › en › latest › src › userguide › memoryviews.html
Typed Memoryviews — Cython 3.3.0 documentation
If you use the pure Python syntax we strongly recommend you use a recent Cython 3 release, since significant improvements have been made here compared to the 0.29.x releases. Typed memoryviews allow efficient access to memory buffers, such as those underlying NumPy arrays, without incurring any Python overhead.
Discussions

How to properly use memoryview in cython?
I’m working on speeding up some code using cython, and figured I could use memoryviews to help. I don’t loop through any arrays, but a function which operates on some arrays is called many times. In my original, pure python module I multiply a 4x4 numpy identity array by a 4x144 numpy array ... More on reddit.com
🌐 r/learnpython
10
3
July 30, 2019
python - Passing/Returning Cython Memoryviews vs NumPy Arrays - Stack Overflow
Memoryviews are designed to work with any type that has Python's buffer interface (for example the standard library array module). Typing as np.ndarray only works with numpy arrays. More on stackoverflow.com
🌐 stackoverflow.com
Convert numpy array to MemoryView object - Stack Overflow
I'm trying to convert a numpy array to a MemoryView object because I have to communicate between two programs. The one can only handle NumPy arrays and the other only MemoryView objects. Convertin... More on stackoverflow.com
🌐 stackoverflow.com
ndarray does not accept memoryview for buffer= under python2
though it succeeds if we pass memoryview to array(): More on github.com
🌐 github.com
4
June 2, 2015
🌐
GitHub
github.com › numpy › numpy › issues › 8408
Allow numpy to copy internal buffer into memoryview · Issue #8408 · numpy/numpy
December 21, 2016 - mymemoryview = MyMemoryView() # pointer on a 24 bytes buffer vertices = np.array([0, -0.5, 0.5, 0.5, -0.5, 0.5], dtype=np.float32) wrapper = np.array(mymemoryview, copy=False, dtype=vertices.dtype) # Wrap my memoryview into a numpy array without copy np.copyto(wrapper, vertices, casting='no')
Author: numpy
🌐
Cython
cython.readthedocs.io › en › 0.29.x › src › userguide › memoryviews.html
Typed Memoryviews — Cython 0.29.37 documentation
Typed memoryviews allow efficient access to memory buffers, such as those underlying NumPy arrays, without incurring any Python overhead.
🌐
Simonwenkel
simonwenkel.com › notes › programming_languages › python › cython-memory-views-of-numpy-arrays.html
Cython Memory Views of NumPy Arrays - SimonWenkel.com
October 4, 2020 - The following functions are evaluated on numpy arrays of dimensions (1x1), (10x10), (100x100). On larger arrays (1000x1000, 10000x10000) only numba and cython memory functions were evaluated. Each function is evaluated 1000 times on each input array. def native_python(M): """Native Python function to compute sin of every element in a NumPy array """ for i in range(M.shape[0]): for j in range(M.shape[1]): M[i,j] = math.sin(M[i,j]) return M
🌐
Apprize
apprize.best › python › cython › 10.html
Cython, NumPy, and Typed Memoryviews - Cython (2015)
This behavior is conceptually—if ... that of Python lists, where slice assignment copies data, and regular assignment simply creates another variable by which to access the same data. We can also use the copy or copy_fortran method to generate a C- or Fortran-contiguous copy of a memoryview’s buffer, respectively. Once a buffer has been acquired, we can slice it like a NumPy ndarray to get another typed memoryview that shares the buffer: ... Like NumPy arrays, typed memoryviews ...
🌐
Google Groups
groups.google.com › g › cython-users › c › AYFMrvSTVr4
creating a memoryview from scratch
My suggestion would be to not touch either __array__ or memoryviews, but either one of: a) Implement the Cython special __getbuffer__ method on a cdef class which has a pointer b) Allocate the memory as a NumPy array in the first place (you can almost always do this if you need to copy anyway?)
🌐
Reddit
reddit.com › r/learnpython › how to properly use memoryview in cython?
r/learnpython on Reddit: How to properly use memoryview in cython?
July 30, 2019 - I cast both as numpy arrays using np.asarray on each, and multiply as normal (array1 * array 2). Cython compiles fine. When executing the code however, I get a value error: “operands could not be broadcast together with shapes (4,4) (4,0)” · Strange, while debugging the original code the second array has shape (4,144), not (4,0). What am I doing wrong? Am I misunderstanding memoryviews?
Find elsewhere
🌐
Python Data Science Handbook
jakevdp.github.io › blog › 2012 › 08 › 08 › memoryview-benchmarks
Memoryview Benchmarks | Pythonic Perambulations
In particular, the slicing operation when we call X[i] and X[j] must generate a new numpy array each time, which leads to a lot of python overhead in reference counting, etc. This is the reason that the cython team introduced typed memoryviews in cython v0.16.
🌐
Codecademy
codecademy.com › docs › python › built-in functions › memoryview()
Python | Built-in Functions | memoryview() | Codecademy
August 26, 2023 - Learn the basics of Python 3.13, one of the most powerful, versatile, and in-demand programming languages today. ... Where obj is the object to create a memoryview of, and mv is the memoryview created. Note: memoryview() can only be used on objects that support the buffer protocol and have a readable or writable buffer interface, such as byte, bytearray, array.array, numpy ...
🌐
GitHub
github.com › cython › cython › blob › master › docs › src › userguide › memoryviews.rst
cython/docs/src/userguide/memoryviews.rst at master · cython/cython
Cython memoryviews support nearly all objects exporting the interface of Python new style buffers. This is the buffer interface described in PEP 3118. NumPy arrays support this interface, as do :ref:`view_cython_arrays`. The "nearly all" is because the Python buffer interface allows the elements in the data array to themselves be pointers; Cython memoryviews do not yet support this.
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › frombuffer()
Python Numpy frombuffer() - Convert Buffer to Array
April 10, 2025 - The frombuffer() function in NumPy is a powerful tool for converting data that resides in a buffer, such as Python bytes or other byte-like objects, into a NumPy array. This is especially useful when working with binary data stored in files, ...
Top answer
1 of 1
14

Memoryviews are a more recent addition to Cython, designed to be an improvement compared to the original np.ndarray syntax. For this reason they're slightly preferred. It usually doesn't make too much difference which you use though. Here are a few notes:

Speed

For speed it makes very little difference - my experience is that memoryviews as function parameters are marginally slower, but it's hardly worth worrying about.

Generality

Memoryviews are designed to work with any type that has Python's buffer interface (for example the standard library array module). Typing as np.ndarray only works with numpy arrays. In principle memorviews can support an even wider range of memory layouts which can make interfacing with C code easier (in practice I've never actually seen this be useful).

As a return value

When returning an array from Cython to code Python the user will probably be happier with a numpy array than with a memoryview. If you're working with memoryviews you can do either:

return np.asarray(mview)
return mview.base

Ease of compiling

If you're using np.ndarray you have to get the set the include directory with np.get_include() in your setup.py file. You don't have to do this with memoryviews, which often means you can skip setup.py and just use the cythonize command line command or pyximport for simpler projects.

Parallelization

This is the big advantage of memoryviews compared to numpy arrays (if you want to use it). It does not require the global interpreter lock to take slices of a memoryview but it does for a numpy array. This means that the following code outline can work in parallel with a memoryview:

cdef void somefunc(double[:] x) nogil:
     # implementation goes here

cdef double[:,:] 2d_array = np.array(...)
for i in prange(2d_array.shape[0]):
    somefunc(2d_array[i,:])

If you aren't using Cython's parallel functionality this doesn't apply.

cdef classes

You can use memoryviews as attributes of cdef classes but not np.ndarrays. You can (of course) use numpy arrays as untyped object attributes instead.

🌐
w3resource
w3resource.com › python-exercises › extended-data-types › python-extended-data-types-index-memory-views-exercise-3.php
NumPy memory views in Python: 1D and 3D array examples
August 11, 2025 - Write a Python script to generate a 3-dimensional NumPy array, create a memory view, and then display the dimensions and a slice from the array.
🌐
Medium
prrasad.medium.com › memory-view-python-performance-improvement-method-c241a79e9843
Memory view -Python Performance Improvement method | by Prasad | Medium
April 26, 2023 - NumPy arrays can be created from memory view objects, which allows for fast array operations without copying data. Image Processing: Memory view is commonly used in image processing applications.