Data Import & Export - New Features in Maple 2020 - Maplesoft

What's New in Maple 2020

Data Import and Export

Maple 2020 includes these updates to data import and export.

Read Part of an Audio File 

The AudioTools:-Read command has a new samples option which enables reading part of an audio file.
Here the interval 10^3 .. 60*10^3; is specified, which indicates that only samples 1000 to 60000 will be read from the specified file.
 

audFile := FileTools:-JoinPath([ 

violinNote_sub := AudioTools:-Read(audFile, samples = `^`(10, 3) .. `+`(`*`(60, `*`(`^`(10, 3)))));  

Typesetting:-mprintslash([violinNote_sub := MATRIX([[
 

FileTools:-Walk 

The new FileTools:-Walk command generates an iterator to traverse subdirectories under a given directory. 

with(FileTools); -1 

iterator := Walk(JoinPath([ 

Typesetting:-mprintslash([iterator := Vector(3, {(1) = Typesetting:-mi(
 

for r in iterator do print(r:-dir, r:-subdirs, r:-files) end do;

 

C:\Program Files\Maple 2020\data\help
C:\Program Files\Maple 2020\data\help\FileTools
C:\Program Files\Maple 2020\data\help\ImportData
C:\Program Files\Maple 2020\data\help\MapleTA
C:\Program Files\Maple 2020\data\help\MapletBuilder
C:\Program Files\Maple 2020\data\help\Optimization
C:\Program Files\Maple 2020\data\help\Worksheet
C:\Program Files\Maple 2020\data\help\XMLTools
C:\Program Files\Maple 2020\data\help\XMLTools
C:\Program Files\Maple 2020\data\help\XMLTools
 

Import and Export of BSON and UBJSON Files 

The Import and Export commands now support and import and export of BSON and UBJSON files. These are both binary file formats modeled after the JSON format. They store structured expressions in a manner similar to JSON.
The BSON format can store additional types of data, including byte arrays and date/time objects.  The latter are translated to Maple
Time objects upon import.UNDHR := Import( 

Typesetting:-mprintslash([UNDHR := TABLE([`, "event" = "United Nations Declaration of Human Rights", "location" = TABLE(["city" = "Paris"..." align="center" border="0">
Typesetting:-mprintslash([UNDHR := TABLE([`, "event" = "United Nations Declaration of Human Rights", "location" = TABLE(["city" = "Paris"..." align="center" border="0">
Typesetting:-mprintslash([UNDHR := TABLE([`, "event" = "United Nations Declaration of Human Rights", "location" = TABLE(["city" = "Paris"..." align="center" border="0">
 

Date(UNDHR[ 

Typesetting:-mrow(Typesetting:-mi(
 

ImportMatrix 

The ImportMatrix command has been updated with two new options: direct and fill.
The
direct option enables parsing data from strings and ByteArrays (in addition to files and URLs):
 

ImportMatrix( 

Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(

 

The fill option specifies a default value for missing data when the input is ragged; a ragged input is an input in which some rows have fewer entries than others. 

In the following example, the first row has four entries while the second and third are underspecified, in which case the fill value of 999 is used. 

ImportMatrix( 

Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(
 

Data conversions to and from Python 

The convert command now allows explicit conversion of certain Maple expressions to their Python counterparts and vice-versa. 

In the following example we convert three expressions to Python expressions: 

pythonSet := convert({1, 5, 7}, python);  

Typesetting:-mprintslash([pythonSet := "], [""])" align="center" border="0">
 

pythonDict := convert(table([ 

Typesetting:-mprintslash([pythonDict := "], ["
 

pythonMatrix := convert(rtable(1 .. 2, 1 .. 3, [[99, 44, -31], [29, 92, 67]], subtype = Matrix), python);  

Typesetting:-mprintslash([pythonMatrix := "], [""])" align="center" border="0">
 

These inputs are suitable as input to Python:-EvalFunction, provided the underlying Python data types match: 

result := Python:-EvalFunction( 

Typesetting:-mprintslash([result := "], [""])" align="center" border="0">
 

We can also convert certain Python expressions into Maple expressions:convert(pythonSet, set);  

{1, 5, 7}
 

convert(pythonDict, table);  

Typesetting:-mprintslash([TABLE([
 

convert(result, Matrix);  

Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mrow(Typesetting:-mo(