79673334

Date: 2025-06-20 11:56:20
Score: 1
Natty:
Report link

As per numpy documentation, the np.array doesnt have buffer input parameter irrespective of the homogenous or heterogeneous datatypes.

But, np.ndarray does have the buffer input parameter option.

Sharing the code with revision with np.ndarray.

import numpy as np

from multiprocessing import shared_memory

my_dtype = [('name', 'U10'), ('age', 'i4'), ('weight', 'f4')]

data = [('Rex', 9, 81.0), ('Fido', 3, 27.0)]

shm = shared_memory.SharedMemory(create=True, size=np.array(data, dtype=my_dtype).nbytes)

shared_array = np.ndarray(len(data), dtype=my_dtype, buffer=shm.buf)

shared_array[:] = data

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: bharathrajad