I've got a python script which generates graphs like the following both:
Now I'd like to initialize variables by their names:
sess.run(g1.initializer_op, feed_dict = {
g1.graph.get_tensor_by_name("sample_data:0"): [1,2,3,4]
})
Therefore, I need all variables to be named equally in all graph instances
However, at the moment each variable in the second graph gets a "_1" suffix.
How do I solve this problem?
Two different variables can't have the same name in tensorflow. That is why tensorflow adds "_1" to all variables which name already exists. If you want to use identical variables for all graphs, you have to create that variables in a tf.variable_scope and set reuse=True for each Graph you create after the first one.
Related
This answer mentions that either
fig = plt.figure()
fig.patch.set_facecolor('black')
or
plt.rcParams['figure.facecolor'] = 'black'
will change the value in the rcParams dictionary for the key 'figure.facecolor'.
Suppose that my script has made several changes to the values in a nondeterministic way based on user interaction, and I want to undo all of that and go back to matplotlib's default parameters and behavior.
In the beginning of the script I could check matplotlib.rcParams and store either the whole dictionary, or values for certain keys, and then restore them one at a time or with the .update() method, but I don't know if that's wise because I don't know how else the matplotlib.RcParams instance is used (it's not just a dictionary). It does have a .setdefault() method but I can't understand what help returns on that:
Help on method setdefault in module collections.abc:
setdefault(key, default=None) method of matplotlib.RcParams instance
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
Is there some kind of restore the original default values feature, or should I just wing-it by updating the whole thing with the copy that I've stored?
Per my understanding and answers to How to recover matplotlib defaults after setting stylesheet you should be able to do this:
import matplotlib
matplotlib.rcParams.update(matplotlib.rcParamsDefault)
You could also check the site-packages/matplotlib/mpl-data folder for the file named matplotlibrc. It should have the entire default values there.
I am beginner in tesnor flow. Trying to understand about various API's and features. For most of the API's in tensor flow has name argument like shown below
# Create a variable.
w = tf.Variable(0, name="abc">)
In most of the programming example "w" is used. I am not getting when name optional argument is used for example how "abc" is used either inside the variable function and how it used in following lines after executing above statement. Kindly help.
Name argument is used in most cases so you can restore your variables from a saved checkpoint. Check this https://www.tensorflow.org/guide/saved_model . Furthermore it is helpful for finding your variables or operations that are visualized in the graph through tensorboard.
I'm new to python and I'm trying to keep part of the following:
'/this/is/my/path'
and I would like to keep this:
'/my/path'
My problem is that the path is dynamic and the length is not the same all the times. And practically I would like to 'delete' the first two parts.
If I use this:
os.getcwd().split("/")[2:5]
my problem is that is not dynamic and also it converts it into a list that I do not want.
Any ideas?
I can't figure out if it is possible to do something like
f_L0(FL)=(stats FL using ($8) name "L", \
L = L_mean, \
1)
Gnuplot keeps complaining: ')' expected and points to FL inside the function.
Any ideas how to define some function like this?
p.s. my gnuplot is 4.6 (Feb2014).
UPDATE:
since this is not possible, it seems, i would just do some analysis in Octave and output it to the file :)
No, you cannot use stats inside of inline funcitons. Gnuplot functions are very basic and can contain only 'regular' mathematical function which compute a single numerical value. You cannot get access to data files inside of functions.
The stats command is command, which is the only command besides plot and splot which has access to data files.
The use of stats is as follows: You must use it as standalone command like
stats 'filename' using 8 name "L"
after which you have access to many variables which contain results from calculations on your data (column 8 in file filename). L_mean is one of those variables, for more see show variables after having executed stats.
However, you can do many calculations inside the using statement. To subtract the mean from you data, use e.g.:
stats 'filename' using 8 name "L"
plot 'filename' using ($8-L_mean)
Hello I'm trying to write a function which reads a certain type of spreadsheet and creates vectors dynamically from it's data then returns said vectors to the workspace.
My xlcs is structured by rows, in the first row there is a string which should become the name of the vector and the rest of the rows contain the numbers which make up the vector.
Here is my code:
function [ B ] = read_excel(filename)
%read_excel a function to read time series data from spreadsheet
% I get the contents of the first cell to know what to name the vector
[nr, name]=xlsread(filename, 'sheet1','A2:A2');
% Transform it to a string
name_str = char(name);
% Create a filename from it
varname=genvarname(name_str);
% Get the numbers which will make up the vector
A=xlsread(filename,'B2:CT2');
% Create the vector with the corect name and data
eval([varname '= A;']);
end
As far as I can tell the vector is created corectly, but I have no ideea how to return it to the workspace.
Preferably the solution should be able to return a indeterminate nr of vectors as this is just a prototype and I want the function to return a nr of vectors of the user's choice at once.
To be more precise, the vector varname is created I can use it in the script, if I add:
eval(['plot(',varname,')'])
it will plot the vector, but for my purposes I need the vector varname to be returned to the workspace to persist after the script is run.
I think you're looking for evalin:
evalin('base', [varname '= B;']);
(which will not work quite right as-is; but please read on)
However, I strongly advise against using it.
It is often a lot less error-prone, usually considered good practice and in fact very common to have predictable outcomes of functions.
From all sorts of perspectives it is very undesirable to have a function that manipulates data beyond its own scope (i.e., in another workspace than its own), let alone assign unpredictable data to unpredictable variable names. This is unnecessarily hard to debug, maintain, and is not very portible. Also, using this function inside other functions does not what someone who doesn't know your function would think it does.
Why not use smoething like a structure:
function B = read_excel(filename)
...
B.data = xlsread(filename,'B2:CT2');
B.name = genvarname(name_str);
end
Then you always have the same name as output (B) which contains the same data (B.data) and whose name you can also use to reference other things dynamically (i.e., A.(B.name)).
Because this is a function, you need to pass the variables you create to an output variable. I suggest you do it through a struct as you don't know how many variables you want to output upfront. So change the eval line to this:
% Create the vector with the correct name and data
eval(['B.' varname '= A;']);
Now you should have a struct called B that persists in the workspace after running the function with field names equal to your dynamically created variable names. Say for example one varname is X, you can now access it in your workspace as B.X.
But you should think very carefully about this code design, dynamically creating variables names is very unlikely to be the best way to go.
An alternative to evalin is the function assignin. It is less powerfull than evalin, but does exacty what you want - assign a variable in a workspace.
Usage:
assignin('base', 'var', val)