I have a data file which has been calculated from mathematica code and saved in test.txt
, I need to import the data and do new calculation on it, here is the simple part of the code:
prob =
Import["/home/Desktop/test1.txt",
"Table"]
{{"9.780659097977332*^-7"}, {"9.0432074782253*^-7"},
{"9.264934689099364*^-7"}, {"9.516465106429963*^-7"},
{"8.577198332761887*^-7"}, {"1.1079713181045429*^-6"}}
alpha = 1.1;
t = Length[prob];
Do[
Shanon = -prob[[i]].Log[prob[[i]]] + Shanon, {i, 1, t}]
Print[{alpha, Shanon}]
and here is the output,
{1.1,-1.1079713181045429*^-6 Log[1.1079713181045429*^-6]-8.577198332761887*^-7 Log[8.577198332761887*^-7]-9.0432074782253*^-7 Log[9.0432074782253*^-7]-9.264934689099364*^-7 Log[9.264934689099364*^-7]-9.516465106429963*^-7 Log[9.516465106429963*^-7]-9.780659097977332*^-7 Log[9.780659097977332*^-7]}
I have been tried different ways including Flatten
, ScientificForm
,...! I am not sure if there is a problem in the way of importing the data or in the format of data.
Flatten
the input, transform those strings into numbers withToExpression
, set an initial value forShanon=0
before theDo
loop, use simple*
instead of the.
dot product operator for simple multiplication... $\endgroup$