I have a file with total 4950
values like:
0.012345678912345678
I read the file using:
a = numpy.genfromtxt(file_name, dtype=str, delimiter=',') # a.shape = (4950L, 1L) #dtype=str as I don't want to compromise accuracy
#say a == ['0.000000000000000001', -'0.000000000000000002', ...., '0.000000000004950']
What I am trying to achieve is to obtain a matrix b
of size (100L, 100L)
whose:
- Upper triangular values are filled with values in numpy array 'a'.
- Lower triangular values are filled with values in numpy array 'a' but multiplied by -1.
- The diagonal consists of zeros only.
Example(The accuracy matters):
array = ['1','2','-3','-5','6','-7'] # In reality the data is up to 18 decimal places.
final_matrix = [
['0','1','2','-3'],
['-1',0,'-5','6'],
['-2','5','0','-7'],
['3','-6','7','0']
]
What is the most efficient way to achieve this?