(Sorry for screwing up the thread; I messed up my list subscription.
This is a response to
https://mail.python.org/pipermail/pythondotnet/2014-May/001525.html )
Thanks, Jeffrey, that's awesome. Since the pointer can be directly
accessed, np.frombuffer() can be used to avoid a copy.
src_hndl = GCHandle.Alloc(src, GCHandleType.Pinned)
try:
src_ptr = src_hndl.AddrOfPinnedObject().ToInt32()
bufType = ctypes.c_double*len(src)
cbuf = bufType.from_address(src_ptr)
dest = np.…
[View More]frombuffer(cbuf, dtype=cbuf._type_)
finally:
if src_hndl.IsAllocated: src_hndl.Free()
Dave Cook
[View Less]
I need to copy a .NET Array (e.g. Double[] or Byte[]) to a numpy array, but
it seems the only way to do so is element by element, which is very slow.
Since we are copying a lot of data in real time, it creates a real
bottleneck.
Alternatively, efficient conversion of the .NET array to a Python style
byte string would allow numpy.fromstring() to be used for creating the
numpy array.
(I see a similar question went unanswered on the list in August 2011, but I
was hoping someone may have figured …
[View More]it out by now.)
Thanks,
Dave Cook
[View Less]