Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
MaxRange | Input | number | Mandatory | A value for the end of the range(inclusive) |
Preamble | Input | string | Mandatory | Required preamble |
Sum | Input | boolean | False | If True, sum the squared values |
OutputFile | Input | string | Mandatory | Allowed values: [‘txt’] |
OutputWorkspace | Output | MatrixWorkspace | Mandatory | A workspace containing the squares |
An example python algorithm.
This creates a workspace with a value that increases as the square of the bin index. It also optionally logs a message and saves a file.
Example
#import the os path libraries for directory functions
import os
#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "Square.txt")
# create histogram workspace
ws=Squares(MaxRange='20', Preamble='Hello', Sum=True, OutputFile=savefile)
print "The first five values are:"
print ws.readY(0)[0:5]
#clean up the file I saved
os.remove(savefile)
Output:
The first five values are:
[ 1. 4. 9. 16. 25.]
Categories: Algorithms | PythonAlgorithms
Python: Squares.py