Python numpy.matlib() Examples

The following are 2 code examples of numpy.matlib(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module numpy , or try the search function .
Example #1
Source File: example_numpy.py    From ringbuffer with Apache License 2.0 5 votes vote down vote up
def writer(ring):
    for i in range(10000):
        m = numpy.matlib.randn(25, 100)
        x = numpy.ctypeslib.as_ctypes(m)
        try:
            ring.try_write(x)
        except ringbuffer.WaitingForReaderError:
            print('Reader is too slow, dropping %r' % x)
            continue

        if i and i % 100 == 0:
            print('Wrote %d so far' % i)

    ring.writer_done()
    print('Writer is done') 
Example #2
Source File: example_numpy.py    From ringbuffer with Apache License 2.0 5 votes vote down vote up
def reader(ring, pointer):
    while True:
        try:
            data = ring.blocking_read(pointer)
        except ringbuffer.WriterFinishedError:
            return

        x = numpy.frombuffer(data)
        x.shape = (25, 100)
        x[1, 1] = 1.1  # Verify it's mutable
        m = numpy.matlib.asmatrix(x)
        norm = numpy.linalg.norm(m)

    print('Reader %r is done' % pointer)