Question:
Is the “-” in the format used below supposed to left-justify the number?
Code:
This section is just generating numbers to demonstrate the problem.
def neuralNetwork(input, weight):
prediction = input * weight
return prediction
weight = 0.5
goalPrediction = 0.8
input = 0.5
for iteration in range(124):
prediction = neuralNetwork(input, weight)
error = (prediction - goalPrediction) ** 2
directionAndAmount = (prediction - goalPrediction) * input
weight = weight - directionAndAmount
Expect the “-” before “11.6g” to left-justify number in 11 character field but it does not.
print(f"Error:{error:-11.6g} Prediction:{prediction:-11.6f}" + \
f" Iteration:{iteration:4d}")
Output:
Error: 0.3025 Prediction: 0.250000 Iteration: 0
Error: 0.170156 Prediction: 0.387500 Iteration: 1
Error: 0.0957129 Prediction: 0.490625 Iteration: 2
Error: 0.0538385 Prediction: 0.567969 Iteration: 3
Error: 0.0302842 Prediction: 0.625977 Iteration: 4
Error: 0.0170348 Prediction: 0.669482 Iteration: 5
Error: 0.0095821 Prediction: 0.702112 Iteration: 6
Error: 0.00538993 Prediction: 0.726584 Iteration: 7
Error: 0.00303184 Prediction: 0.744938 Iteration: 8
Error: 0.00170541 Prediction: 0.758703 Iteration: 9
Error:0.000959292 Prediction: 0.769028 Iteration: 10
Error:0.000539602 Prediction: 0.776771 Iteration: 11