In the following example a 2 by 3 tensor is multiplied by a scalar value (2).
# Build a graph
graph = tf.Graph()
with graph.as_default():
# A 2x3 matrix
a = tf.constant(np.array([[ 1, 2, 3],
[10,20,30]]),
dtype=tf.float32)
...
Variable tensors are used when the values require updating within a session. It is the type of tensor that would be used for the weights matrix when creating neural networks, since these values will be updated as the model is being trained.
Declaring a variable tensor can be done using the tf.Varia...
XSS attacks consist in injecting HTML (or JS) code in a page. See What is cross site scripting for more information.
To prevent from this attack, by default, Django escapes strings passed through a template variable.
Given the following context:
context = {
'class_name': 'large" style=&...
It is possible to create custom routing constraint which can be used inside routes to constraint a parameter to specific values or pattern.
This constrain will match a typical culture/locale pattern, like en-US, de-DE, zh-CHT, zh-Hant.
public class LocaleConstraint : IRouteConstraint
{
pri...
A Bag/ultiset stores each object in the collection together with a count of occurrences. Extra methods on the interface allow multiple copies of an object to be added or removed at once. JDK analog is HashMap<T, Integer>, when values is count of copies this key.
TypeGuavaApache Commons Collec...
This multimap allows duplicate key-value pairs. JDK analogs are HashMap<K, List>, HashMap<K, Set> and so on.
Key's orderValue's orderDuplicateAnalog keyAnalog valueGuavaApacheEclipse (GS) CollectionsJDKnot definedInsertion-orderyesHashMapArrayListArrayListMultimapMultiValueMapFastListMu...
Compare operation with collections - Create collections
1. Create List
DescriptionJDKguavags-collectionsCreate empty listnew ArrayList<>()Lists.newArrayList()FastList.newList()Create list from valuesArrays.asList("1", "2", "3")Lists.newArrayList("1", &...
Suppose we want to count how many counties are there in Texas:
var counties = dbContext.States.Single(s => s.Code == "tx").Counties.Count();
The query is correct, but inefficient. States.Single(…) loads a state from the database. Next, Counties loads all 254 counties with all of the...
select_dtypes method can be used to select columns based on dtype.
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'],
'D': [True, False, True]})
In [2]: df
Out[2]:
A B C D
0 1 1.0 a True
1 2 2.0 b False
2...
To connect to MySQL you need to use the MySQL Connector/J driver. You can download it from http://dev.mysql.com/downloads/connector/j/ or you can use Maven:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version...
When you create a function in TypeScript you can specify the data type of the function's arguments and the data type for the return value
Example:
function sum(x: number, y: number): number {
return x + y;
}
Here the syntax x: number, y: number means that the function can accept two argum...
Example:
function hello(name: string): string {
return `Hello ${name}!`;
}
Here the syntax name: string means that the function can accept one name argument and this argument can only be string and (...): string { means that the return value can only be a string
Usage:
hello('StackOverfl...
You can start the mongo shell by running the following command inside your Meteor project:
meteor mongo
Please note: Starting the server-side database console only works while Meteor is running the application locally.
After that, you can list all collections by executing the following command...
TeX formulae can be inserted in the plot using the rc function
import matplotlib.pyplot as plt
plt.rc(usetex = True)
or accessing the rcParams:
import matplotlib.pyplot as plt
params = {'tex.usetex': True}
plt.rcParams.update(params)
TeX uses the backslash \ for commands and symbols, whic...
In order to include plots created with matplotlib in TeX documents, they should be saved as pdf or eps files. In this way, any text in the plot (including TeX formulae) is rendered as text in the final document.
import matplotlib.pyplot as plt
plt.rc(usetex=True)
x = range(0, 10)
y = [t**2 for t...
public class MyObject{
public DateTime? TestDate { get; set; }
public Func<MyObject, bool> DateIsValid = myObject => myObject.TestDate.HasValue && myObject.TestDate > DateTime.Now;
public void DoSomething(){
//We can do this:
if(this.TestDate....
Dart has a robust async library, with Future, Stream, and more. However, sometimes you might run into an asynchronous API that uses callbacks instead of Futures. To bridge the gap between callbacks and Futures, Dart offers the Completer class. You can use a Completer to convert a callback into a Fut...
When defining a function, use {param1, param2, …} to specify named parameters:
void enableFlags({bool bold, bool hidden}) {
// ...
}
When calling a function, you can specify named parameters using paramName: value
enableFlags(bold: true, hidden: false);
A linked list is a linear collection of data elements, called nodes, which are linked to other node(s) by means of a "pointer." Below is a singly linked list with a head reference.
┌─────────┬─────────┐ ┌─────────┬─────────┐
HEAD ──▶│ data │"pointer"│──▶...
In many Excel applications, the VBA code takes actions directed at the workbook in which it's contained. You save that workbook with a ".xlsm" extension and the VBA macros only focus on the worksheets and data within. However, there are often times when you need to combine or merge data fr...