Relatively new to Python. Have some experience in C++.
I have written a small program that reads a
CSV file (SAMPLE) and initialises two arrays and few values. There are 2 values in each line, and there are 8763 such lines. The first value of each line is put into one array and the second value is put into the second array. The last three values of each array (total 6) are then given to another variable.
I want further calculations as accurate as possible hence I've tried the decimal.Decimal approach for Float Point Arithmetic, but for some reason, it's not that accurate. I think I'm using it wrong. It is still in an acceptable tolerance.
Also, would like to know if there is a better/efficient way to initialise the array and/or variables.
Here is code:
alpha = np.zeros(8763, dtype='float32') # Edited in later for clarity gamma = np.zeros(8763, dtype='float32') # Edited in later for clarity rf = 100 counter = 0 with open('CSVData.csv', 'r') as csv_file_in: csv_reader = csv.reader(csv_file_in) for line in csv_reader: alpha[counter] = (float(decimal.Decimal(line))) # Alpha Angle Initialized gamma[counter] = (float(decimal.Decimal(line))) # Gamma Angle Initialized if counter == 8762: break counter = counter + 1 csv_file_in.close() # Initializing last 6 parameters C_NSX = rf * alpha C_NSY = rf * gamma C_EWX = rf * alpha C_EWY = rf * gamma NSC = int(alpha) EWC = int(gamma)
Here the value of C_NSX should be 2790 but is 2789.9999185. (Debug Image)
EDIT: ADDED INFO ON THE PURPOSE OF THIS CODE
Following is my problem statement:
There is a matrix of octagons, for example, 4 octagons in a row and 3 such rows. So 4 columns and 3 rows of octagons. But they are not arranged in a perfect rectangle form.
The first Octagon, O(0,0) has coordinates(0,0), while the one at its right and the one at the bottom are at a bit offset. So O(0,1) has coordinates (15,50) and O(1,0) has coordinates (30,15). This information is enough to define the whole array of octagons. Now next requirement is to find how much is the net visible area of these octagons. In the first example, as the coordinates are far away, there would be no overlapping and total visible area is simply...
Total_Visible_Area = Area_of_Single_Octagon * No_Of_Rows * No_Of_Columns
But when the coordinates are a bit complex, for example, Case 2: Here, the distance between the adjacent octagons is less than their width and hence they are overlapping. Coordinates also are negative (which does not matter much actually, just something to note). Now to determine the visible area for this I wrote the following function.
The piece of code that I have written above is the first step to calculate all these. Each case is defined using Alpha, Gamma, C_NSX, C_NSY, C_EWX, C_EWY, NSC and EWC. Among these Alpha and Gamma have 8760 different values (mostly zeroes) and all others (capitals) are constants. I have to find the overlapping area in each of the 8760 cases. The code for finding those I had discussed here earlier, and thought won't be necessary to bring out again. After that last question, I have moved to python from CPP and started learning OpenCV.