2D binary mapΒΆ

This module implement 2D bit array, where every element is one or zero and takes single bit. Based on bitarray. Still work in progress..

It is not complete yet, not fully tested (wrote several test in /test, but lazy for now the TM is more fun :).

There are many possibilities for optimizations.

import sys
sys.path.append('../lib')
import numpy as np
from bmap2D import *
bm = BMap2D(nrows=5, ncols=20)
bm
0| 00000000000000000000
1| 00000000000000000000
2| 00000000000000000000
3| 00000000000000000000
4| 00000000000000000000
bm.rand_item
bitarray('01111110110000010001')
bm.rand_bmap
bitarray('0001001110010000000111101010100000011110011000101111001101001000100010001111110100110010010100111101')
bm.set(bm.rand_bmap)
bm
0| 10001010010110110000
1| 10000010101100111110
2| 11001001000111100000
3| 11001010001100101101
4| 11101001000110111100
bm[1,:] = 0
bm
0| 10001010010110110000
1| 00000000000000000000
2| 11001001000111100000
3| 11001010001100101101
4| 11101001000110111100
bm[:,2] = 1
bm
0| 10101010010110110000
1| 00100000000000000000
2| 11101001000111100000
3| 11101010001100101101
4| 11101001000110111100
bm[:,[4,5,6,7,8]] = 1
bm
0| 10101111110110110000
1| 00101111100000000000
2| 11101111100111100000
3| 11101111101100101101
4| 11101111100110111100
bm[:,4:8] = 0
bm
0| 10100000010110110000
1| 00100000000000000000
2| 11100000000111100000
3| 11100000001100101101
4| 11100000000110111100
bm[1:40] = 0 #1D access
bm
0| 10000000000000000000
1| 00000000000000000000
2| 11100000000111100000
3| 11100000001100101101
4| 11100000000110111100
bm.erase()
bm
0| 00000000000000000000
1| 00000000000000000000
2| 00000000000000000000
3| 00000000000000000000
4| 00000000000000000000
bm[1:3,5:10] = 1
bm
0| 00000000000000000000
1| 00000111111000000000
2| 00000111111000000000
3| 00000111111000000000
4| 00000000000000000000
bm[0,:] = bm.rand_item
bm
0| 11011111010010100101
1| 00000111111000000000
2| 00000111111000000000
3| 00000111111000000000
4| 00000000000000000000
bm.rotate()
bm
0| 10000
1| 10000
2| 00000
3| 10000
4| 10000
5| 11110
6| 11110
7| 11110
8| 01110
9| 11110
10| 01110
11| 00000
12| 10000
13| 00000
14| 10000
15| 00000
16| 00000
17| 10000
18| 00000
19| 10000
bm.rotate()
bm
0| 11011111010010100101
1| 00000111111000000000
2| 00000111111000000000
3| 00000111111000000000
4| 00000000000000000000
bm >> 2
bm
0| 00000000000000000000
1| 00000000000000000000
2| 11011111010010100101
3| 00000111111000000000
4| 00000111111000000000
bm.bmap = bm.bmap << 40
bm
0| 11011111010010100101
1| 00000111111000000000
2| 00000111111000000000
3| 00000000000000000000
4| 00000000000000000000
bm[1,:] & bm.rand_item
0| 00000110111000000000
bm[0,:] | bm[1,:]
0| 11011111111010100101
bm.coords1D([(1,1),(5,5),(0,7)])
[6, 30, 7]
bm.coords2D([5,30,42,55])
[(1, 5), (6, 10), (8, 2), (11, 15)]