HP Forums
table data - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: table data (/thread-12477.html)



table data - compsystems - 02-22-2019 12:23 AM

Hello,
Python has an object type called DICTIONARY that in xcas / hpprime is table(), but python, only manages a few types of data in relation to xcas, which can operate with many more and powerfull math types.

Examples of use


PHP Code:
tblA := table"float_1" 5.0 "integer_2" 5"complex_4" 3+4*i"identifier_6" var01"list_7" = [9,[8,7],[6,5,4]],   "symbolic_8" x+y*"rational_9" 3/4,  "string_12" "Hello",  "set_2" seta,a],  "polynomial_10" poly11, -611, -] , "matrix" = [[1,2],[3,4]], "vector" = [9,8,7,6,5,4], "function_13" f(x):=x+1  )
[
enterreturns
table
… )


tblA"float_1" ], tblA"integer_2" ], tblA"complex_4" ], tblA"identifier_6" ], tblA"list_7" ], tblA"symbolic_8" ], tblA"rational_9" ], tblA"string_12" ], tblA"function_13" ],  tblA[  "set_2" ],  tblA[  "polynomial_10" ], tblA[  "matrix"  ],  tblA[  "vector"  ]
[
enterreturns
5.0
,5,3+4*i,var01,[9,[8,7],[6,5,4]],x+i*y,3/4,"Hello", (x)->x+1,set[a,b,c],poly1[1,-6,11,-6],[[1,2],[3,4]],[9,8,7,6,5,4]


typetblA"float_1" ] ), typetblA"integer_2" ] ), typetblA"complex_4" ] ), typetblA"identifier_6" ] ), typetblA"list_7" ] ), typetblA"symbolic_8" ] ), typetblA"rational_9" ] ), typetblA"string_12" ] ), typetblA"function_13" ] ), typetblA[  "set_2" ] ), typetblA[  "polynomial_10"  ]), typetblA[  "matrix"  ]), typetblA[  "vector"  ]), typetblA
[
enterreturns

Xcas
:
realintegercomplexidentifiervectorexpressionrationalstringfuncvectorvectorvectorvectorDOM_MAP

hpprime
:
DOM_FLOATDOM_INTDOM_COMPLEXDOM_IDENTDOM_LISTDOM_SYMBOLICDOM_RATDOM_STRINGDOM_FUNC,DOM_LISTDOM_LISTDOM_LISTDOM_LISTDOM_MAP


typetblA"float_1" ] ), typetblA"integer_2" ] ), typetblA"complex_4" ] ), typetblA"identifier_6" ] ), typetblA"list_7" ] ), typetblA"symbolic_8" ] ), typetblA"rational_9" ] ), typetblA"string_12" ] ), typetblA"function_13" ] ), typetblA[  "set_2" ] ), typetblA[  "polynomial_10"  ]), typetblA[  "matrix"  ]), typetblA[  "vector"  ]), typetblA)  ] .+ 0
[enterreturns
[1,2,4,6,7,8,10,12,13,7,7,7,7,17]


tblA"list_7" ][0] [enterreturns
9

tblA
"list_7" ][[1]] [enterreturns




RE: table() data - toml_12953 - 02-22-2019 04:00 PM

I get a syntax error and the cursor points after the var01 here:

tblA := table( "float_1" = 5.0 , "integer_2" = 5, "complex_4" = 3+4*i, "identifier_6" = var01


RE: table() data - compsystems - 02-22-2019 07:33 PM

Hello,
Delete the space between set and the bracket []
set [] => set[], same for polynomial poly1[], I do not know why the hpprime, when pasting the data adds a space before []


##################

Converting a rectangular array type matrix into a table
the positions start at (0,0)

Example
PHP Code:
MA:=[[9,8],
[
7,3+4*i]] 

table(MA) [enter] returns

PHP Code:
table(
(
0,0) = 9,
(
0,1) = 8,
(
1,0) = 7,
(
1,1) = 3+4*i



for the inverse process, that is, convert a table to a matrix, Note that this must have the form


PHP Code:
table(
(
0,0) = element1,
(
0,1) = element2,
...



or

PHP Code:
table(
[
0,0] = element1,
[
0,1] = element2,
...



Example

PHP Code:
matrix

table(
(
0,0) = 9,
(
0,1) = 8,
(
1,0) = 7,
(
1,1) = 3+4*i


)

or

PHP Code:
matrix

table(
[
0,0] = 9,
[
0,1] = 8,
[
1,0] = 7,
[
1,1] = 3+4*i


[enter] returns

PHP Code:
[[9,8],
[
7,3+4*i]] 


/////////////////////////


An alternative way to define tables is using ( : )
PHP Code:
:= table"foo"109:x+y*i"bar"100"baz"1000) [enterreturns
table
(
x+y*i,
"bar" 100,
"baz" 1000,
"foo" 10


But unlike python, Xcas reorders the labels numerically and alphabetically

To extract the tag you can use FOR
PHP Code:
for k in d:
   print(
k) [enterreturns

9
bar
baz
foo 



and to access the values of the label.
PHP Code:
for k in d:
    print(
d[k]) [enterreturns

x
+y*i
100
1000
10