# HP Forums

Full Version: table data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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*i , "rational_9" = 3/4,  "string_12" = "Hello",  "set_2" = set[ a, b ,a, c ],  "polynomial_10" = poly1[ 1, -6, 11, -6 ] , "matrix" = [[1,2],[3,4]], "vector" = [9,8,7,6,5,4], "function_13" = f(x):=x+1  )[enter] returnstable( … )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"  ][enter] returns5.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]type( tblA[ "float_1" ] ), type( tblA[ "integer_2" ] ), type( tblA[ "complex_4" ] ), type( tblA[ "identifier_6" ] ), type( tblA[ "list_7" ] ), type( tblA[ "symbolic_8" ] ), type( tblA[ "rational_9" ] ), type( tblA[ "string_12" ] ), type( tblA[ "function_13" ] ), type( tblA[  "set_2" ] ), type( tblA[  "polynomial_10"  ]), type( tblA[  "matrix"  ]), type( tblA[  "vector"  ]), type( tblA) [enter] returnsXcas:real, integer, complex, identifier, vector, expression, rational, string, func, vector, vector, vector, vector, DOM_MAPhpprime:DOM_FLOAT, DOM_INT, DOM_COMPLEX, DOM_IDENT, DOM_LIST, DOM_SYMBOLIC, DOM_RAT, DOM_STRING, DOM_FUNC,DOM_LIST, DOM_LIST, DOM_LIST, DOM_LIST, DOM_MAP[ type( tblA[ "float_1" ] ), type( tblA[ "integer_2" ] ), type( tblA[ "complex_4" ] ), type( tblA[ "identifier_6" ] ), type( tblA[ "list_7" ] ), type( tblA[ "symbolic_8" ] ), type( tblA[ "rational_9" ] ), type( tblA[ "string_12" ] ), type( tblA[ "function_13" ] ), type( tblA[  "set_2" ] ), type( tblA[  "polynomial_10"  ]), type( tblA[  "matrix"  ]), type( tblA[  "vector"  ]), type( tblA)  ] .+ 0[enter] returns[1,2,4,6,7,8,10,12,13,7,7,7,7,17]tblA[ "list_7" ][0] [enter] returns9tblA[ "list_7" ][[1]] [enter] returns9 `
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
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:
`d := table( "foo": 10, 9:x+y*i, "bar": 100, "baz": 1000) [enter] returnstable(9 = 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) [enter] returns9barbazfoo `

and to access the values of the label.
PHP Code:
`for k in d:    print(d[k]) [enter] returnsx+y*i100100010 `
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :