[Python] in kdb how do you save a 2d matrix into a binary format such that it can be read in...

Discussão em 'Python' iniciado por Stack, Julho 1, 2025.

  1. Stack

    Stack Membro Participativo

    My goal is to save a huge 2d matrix as binary in kdb q, so that my python code can import it as numpy matrix. I played with numpy.fromfile and numpy.memmap but I don't think kdb is writing it into a binary format that numpy can understand. I also tried using the save / set / 0x0 sv commands in kdb but nothing seems to be working. Is there anyway to do this at all?

    For example, in kdb:

    m:(3 4)#12?1.0
    `:/home/davidmoss/matrix set raze m


    Then in python:

    import numpy as np
    matrix = np.fromfile('/home/davidmoss/matrix', dtype=np.float64)
    matrix = np.memmap('/home/davidmoss/matrix', dtype='float64', mode='r', shape=(3,4))


    both of these don't work, what am I missing?

    Continue reading...

Compartilhe esta Página