eval

运行TensorFlow

限于喜欢 提交于 2019-12-02 09:15:22
本文内容参考了 机器学习实战:基于Scikit-Learn和Tensorflow 一书。 安装 pip3 install --upgrade tensorflow 创建计算图并运行 import tensorflow as tf # 创建计算图 x = tf . Variable ( 3 , name = 'x' ) y = tf . Variable ( 4 , name = 'y' ) f = x * x * y + y + 2 # 创建会话,并计算 with tf . Session ( ) as sess : x . initializer . run ( ) y . initializer . run ( ) result = f . eval ( ) # 还可以为所有变量一次性完成初始化 init = tf . global_variables_initializer ( ) with tf . Session ( ) as sess : init . run ( ) result = f . eval ( ) 节点值的生命周期 当求值一个节点时,TensorFlow会自动检测该节点依赖的节点, 并先对这些节点求值。 with tf . Session ( ) as sess : print ( y . eval ( ) ) # w,x的值会被计算两次 print (

基本统计值计算

Deadly 提交于 2019-12-02 09:12:56
“基本统计值计算” 问题分析 1.1 问题分析 基本统计值 需求:给出一组数,对它们有一个概要理解 总个数,求和,平均值,方差,中位数 总个数(len) 求和:for ... in 平均值:求和/总个数 方差:各数据与平均数差的平方的和的平均数 中位数:排序然后 奇数找中间1个,偶数找中间2个取平均 二 “基本统计值计算的实例讲解” 获取多数据输入 通过函数分隔功能 def get_nums(): """获取数据""" nums = [] num = input('请输入数字:').strip() while num != '': nums.append(num) num = input('请输入数字:').strip() return nums def get_len(nums): """获取长度""" count = 0 for num in nums: count += 1 return count # nums = get_num() # print(get_len(nums)) def get_add(nums): """求和""" sum = 0 for num in nums: sum += eval(num) return sum # nums = get_num() # print(get_add(nums)) def get_mean(nums): ""

Javascript - eval() `{}` expression

北城以北 提交于 2019-12-02 08:26:10
问题 Why can a string like "{opacity: 1.0, width: '132px'}" not be evaluated using eval() as is? eval("{opacity: 1.0, width: '132px'}"); // invalid label // {opacity: 1.0, width: '132px'} // ---------------ꜛ eval("v = {opacity: 1.0, width: '132px'}"); // works! 回答1: Why can a string like "{opacity: 1.0, width: '132px'}" not be evaluated using eval() as is? Because the text occurs where a statement or block is expected, not an expression, and so the { denotes the beginning of a block, not the

heredoc with eval code execution

Deadly 提交于 2019-12-02 08:16:51
I've tryed a couple of methods to try and get this working but with no luck! I've got a page like this (Example): <?php $jj = <<<END ?> <h1>blah blah</h1> <p> blah blah blah blah blah blah blah <?php include("file.php"); ?> blah blah</p> <?php END; eval('?>'.$jj.'<?php '); ?> this causes no output what so ever, can not think of a solution! This will not work because eval only expects PHP code (i.e. not surrounded by <?php ?> tags), so the call to eval() will probably fail with a parse error. I would suggest using output buffering instead, for example: <?php //start output buffering, anything

Risks of using PHP eval [duplicate]

跟風遠走 提交于 2019-12-02 08:00:31
Possible Duplicates: When (if ever) is eval NOT evil? when is eval evil in php? Since I found no other way of executing a string from an external file as code, I resorted to utilizing eval(). I am not asking about any code in particular, since examples in my use-case scenario would be trivial - what I want to know is what are the dangers of using eval in php code. I did some research on the subject, but I couldn't find any answer that would satisfy my curiosity. All I was able to find were things like "execution of malicious code", "abusive injections" etc. No examples, and no detailed

asp:hyperLink NavigateURL and Eval functions

こ雲淡風輕ζ 提交于 2019-12-02 07:40:20
问题 What is the correct syntax to add a Eval() function to the NavigateURL attribute of asp:HyperLink? I am trying to achieve the below: NavigateUrl="http://home/?<%# Eval("U_ID") %>" The link should be "http://home? + the value of U_ID" But the syntax isn't right I know. Whats the correct spelling? 回答1: Try with this NavigateUrl='http://home/?<%# Eval("U_ID") %>' or NavigateUrl='<%# "http://home/?" + (string)Eval("U_ID") %>' 回答2: It wasn't works my site. I found the following solution:

Securely running user's code

こ雲淡風輕ζ 提交于 2019-12-02 06:53:13
I am looking to create an AI environment where users can submit their own code for the AI and let them compete. The language could be anything, but something easy to learn like JavaScript or Python is preferred. Basically I see three options with a couple of variants: Make my own language, e.g. a JavaScript clone with only very basic features like variables, loops, conditionals, arrays, etc. This is a lot of work if I want to properly implement common language features. 1.1 Take an existing language and strip it to its core. Just remove lots of features from, say, Python until there is nothing

How to evaluate string that have exponential

倖福魔咒の 提交于 2019-12-02 06:51:52
Javax ScriptEngine and JEval works similarly, you input an string and send it to be evaluated, and it will return you the result of it: In ScriptEngine (almost the same in JEval): System.out.println(engine.eval("2*3+4")); will result in: 10.0 But when I try to make it an exponential: System.out.println(engine.eval("2^3+4")); will result in: 5.0 But it really should result in 12 (2^3 = 8, 8+4=12), so my question is how can I set it up in a way that the string which the will be all the whole equation, will evaluate supporting the exponential, and result correctly? Should I use another library? ^

Eval() display custom value if null

坚强是说给别人听的谎言 提交于 2019-12-02 06:47:27
问题 <td> <asp:Label ID="TypeOfPaintingLabel" runat="server" Text='<%# Eval("TypeOfPainting") %>' /> </td> Does anyone know how this works? I want to display "NA" if there is no value provided to TypeOfPainting . 回答1: by creating a public method You can complete this task very easily like public string testbind(object myvalue) { if (myvalue == null) { return "NA value"; } return myValue.ToString(); } Label Code: <asp:Label ID="TypeOfPaintingLabel" Text='<%# testbind(Eval("TypeOfPainting")) %>'

Why is the eval class giving me a casting error from int to double?

泄露秘密 提交于 2019-12-02 06:24:54
I am trying to make a method that takes a string formula, and solves the integral of that formula by doing a Riemann's sum with very small intervals. I am using the ScriptEngine and ScriptEngineManager classes to evaluate the function (with the eval() method). For some reason, I am getting this error: Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double at sum.integral(sum.java:31) at sum.main(sum.java:13) import java.beans.Expression; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script