I'm trying to chance the style plotting for symbolic functions
But I can't , to plot those functions I used the command ezplot, but not work like command plot
In plot I put the style of line after function, of course defined before, values of variable used in function.
Now I want to do the same with symbolic functions, I want to put a different style like in plot.
I hope that someone can help me with a explicit example, please.
plot is a high level function that accepts the line styles as additional input. In order to alter the appearance of ezplot you'll want to specify the line properties using the graphics handle that is returned by ezplot
h = ezplot('x^2');
set(h, 'LineStyle', ':', 'Marker', '*', 'Color', 'r')
Related
I'm trying to extract the exact coordinates for an atom in specific residues in a PDB file.
The idea is to use a function that finds the coordinates of all oxygens of the cysteines in a file, find the nitrogen coordinates on the histidines in the same file, and calculate the distances between them.
import sys
import os
os.getcwd()
filename = sys.argv[1]
def cys_ox_coord_extr():
with open(filename, "r") as fileobj:
content = fileobj.readlines()
print("Cysteine's oxygen coordinates\n")
for line in content:
if line.startswith("ATOM"):
if str(line.split()[3]) == "CYS" and str(line.split()[2]) == "O":
cys_ox = [line.split()[5], [line.split()[6], line.split()[7], line.split()[8]]]
print(cys_ox)
The function works fine, and I can get the coordinates for this atom type, however, I can't use these results elsewhere.
I can't recall "cys_ox" anywhere outside the function itself, even using `return cys_ox.
Yet, if I print it, the results come out fine.
My goal is to get the coordinates for another atom type in another residue and compute the distances, but it is impossible if I can't use the results outside the function which generates them.
What can I do?
Thank you!!!
as Giacomo suggested,
define a list outside the function, and append cys_ox to the list. So the list has global scope and you can access outside the function. Else you should define global cys_ox at start of function, so python know that such variable should have global scope (and not the default function scope), but you may have many cys_ox, so a list is better. –
Giacomo Catenazzi
I mean to set the default legend font size (and other properties as well) in my Octave script.
Both set (activated separately)
legend_fontsize = 14;
set(0, "defaultlegendlocation", "northoutside");
set(0, "defaultlegendfontsize", legend_fontsize);
produce error: invalid default property specification.
What is the correct syntax?
In Matlab, this suggests it should not throw any error, and it should possibly work.
In theory you are right that this should also work in octave, since according to the manual, octave supports the same syntax, for all kinds of graphical object 'types'.
However, legend is a special case, because it is not implemented as its own graphical object 'type' in octave; instead, as stated in the documentation:
A legend is implemented as an additional axes object with the 'tag'
property set to "legend". Properties of the legend object may be
manipulated directly by using 'set'.
Therefore, this means that the defaultlegendfontsize strategy won't work.
It also means that, since in principle a 'legend' object is an 'axes' object in disguise, set( 0, 'defaultaxesfontsize', 30 ) will work ... but obviously with unintended consequences affecting all axes objects.
You could point that out in the octave bug tracker if you'd like.
In the meantime, you could always do something like the following in your .octaverc as a workaround:
function h = legend( varargin )
% Wrapper to builtin legend function, also setting font to default size of 30
h = builtin( 'legend', varargin{:} )
set( h, 'fontsize', 30 )
endfunction
This effectively shadows the builtin 'legend' command with a custom one, that applies 'default' values as an extra step before returning the handle.
PS: Having said this, one needs to be careful with setting such defaults, in the case of code dissemination and re-use which assumes such defaults are preset in all environments.
This is a common point of caution in R users against creating elaborate .Rprofile files, for instance.
PS 2: Alternatively, a nice approach when you have lots of defaults to apply would be to create a function applydefaults( handle ) which applies all your preferences in one go, and call it at the end of whatever object you want to apply these to. This is what I used to do in my thesis. It may sound like slightly more effort, but you end up thanking yourself 1 month down the line when it's 100% clear what is happening and where the formatting changes came from!
Im using maple Im in worksheetmode I tried using Maple Input and 2D Input and I want to transpose my Matrix A:
A := `<|>`(`<,>`(1, .5, -2), `<,>`(.5, 9/4+b, 5+3*b), `<,>`(-2, 5+3*b, 18+9*b+4*a));
B:= Transpose(A);
When I exectute the sheet I dont get the translated values, there are the same as the input. So my matrix looks like the same as my input matrix plus the function term.
You can see a picture in the following link: Why arent the functions executed?
Meanwhile B:=A^+ is doing it the right way and I get a transposed Matrix. But also other functions only return the function body instead the needed values...
If you are using 2D Input mode (the default) then the extra space you've got between Transpose and the bracketed (B) is interpreted as multiplcation. Get rid of such a space.
Also, either load the package at the start of your document like,
with(LinearAlgebra):
before calling the Transpose command from that package, or call it with it's full name like,
LinearAlgebra:-Transpose(B);
I don't know if this is a problem that others get, but I have code in python that goes like this:
def makemove(board,move,val):
new=board
new[move[0]][move[1]]=val
return new
My problem is that if I use this function by simply doing makemove(game,[0,1],-1) where game equals [[0,0,1],[0,1,0],[1,0,0]] the variable game becomes [[0, -1, 1], [0, 1, 0], [1, 0, 0]].
I have tried to look into functions setting global variables, but I have thus for not found a way to prevent makemove() from setting the variables that you put into it. Is there something obvious that I'm missing?
You need to clone board.
import
new = copy.deepcopy(board)
see https://stackoverflow.com/a/2612815/93910 for other ways of doing this.
Your code sets elements of a variable which is a "reference".
In other words, your variable new is really an array reference to board, i.e. it points to the same memory location. So when you change new, the original variable board gets changed.
Here's another answer on how to think about this: https://stackoverflow.com/a/9697367/93910
This is basically because assignment in Python doesn't mean what you think it does, and lists are mutable sequences.
Lists are Python objects. The name board is merely a label for or reference to that object.
So when you say new=board this means "let the name new reference the same object as the name board".
In Python every object has a unique identifier that you can retrieve using id(). Let's create a board, do the assignment and see what happens:
In [1]: board = [[0,0,1],[0,1,0],[1,0,0]]
In [2]: new = board
In [3]: id(new), id(board)
Out[3]: (34495504136, 34495504136)
new and board are referencing the same object.
Since a list is a mutable sequence you can change it without getting an error.
So if you want to play with any mutable sequence inside a function without modifying the original, you should use copy.deepcopy first to make a copy and modify that.
I am new to theano, can anyone help me defining a theano function like this:
Basically, I have a network model looks like this:
y_hat, cost, mu, output_hiddens, cells = nn_f(x, y, in_size, out_size, hidden_size, layer_models, 'MDN', training=False)
here the input x is a tensor:
x = tensor.tensor3('features', dtype=theano.config.floatX)
I want to define two theano functions for later use:
f_x_hidden = theano.function([x], [output_hiddens])
f_hidden_mu = theano.function([output_hiddens], [mu], on_unused_input = 'warn')
the first one is fine. for the second one, the problem is both the input and the output are output of the original function. it gives me error:
theano.gof.fg.MissingInputError: An input of the graph, used to compute Elemwise{identity}(features), was not provided and not given a value.
my understanding is, both of [output_hiddens] and [mu] are related to the input [x], there should be an relation between them. I tried define another theano function from [x] to [mu] like:
f_x_mu = theano.function([x], [mu]),
then
f_hidden_mu = theano.function(f_x_hidden, f_x_mu),
but it still does not work. Does anyone can help me? Thanks.
The simple answer is NO WAY. In here
Because in Theano you first express everything symbolically and afterwards compile this expression to get functions, ...
You can't use the output of theano.function as input/output for another theano.function since they are already a compiled graph/function.
You should pass the symbolic variables, such as x in your example code for f_x_hidden, to build the model.