Tutorial by Examples: er

The function np.loadtxt can be used to read csv-like files: # File: # # Col_1 Col_2 # 1, 1 # 2, 4 # 3, 9 np.loadtxt('/path/to/dir/csvlike.txt', delimiter=',', comments='#') # Output: # array([[ 1., 1.], # [ 2., 4.], # [ 3., 9.]]) The same file could be read ...
# example data DT = as.data.table(mtcars, keep.rownames = TRUE) To rearrange the order of columns, use setcolorder. For example, to reverse them setcolorder(DT, rev(names(DT))) This costs almost nothing in terms of performance, since it is just permuting the list of column pointers in the da...
# example data DT = data.table(iris) To modify factor levels by reference, use setattr: setattr(DT$Species, "levels", c("set", "ver", "vir") # or DT[, setattr(Species, "levels", c("set", "ver", "vir"))] The sec...
# example data set.seed(1) n = 1e7 ng = 1e4 DT = data.table( g1 = sample(ng, n, replace=TRUE), g2 = sample(ng, n, replace=TRUE), v = rnorm(n) ) Matching on one column After the first run of a subsetting operation with == or %in%... system.time( DT[ g1 %in% 1:100] )...
// application/controllers/Company_controller.php <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); class Company_controller extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('companies_mo...
Let's create an Enumerator for Fibonacci numbers. fibonacci = Enumerator.new do |yielder| a = b = 1 loop do yielder << a a, b = b, a + b end end We can now use any Enumerable method with fibonacci: fibonacci.take 10 # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
You can do a permissions check when sending an Intent to a registered broadcast receiver. The permissions you send are cross-checked with the ones registered under the tag. They restrict who can send broadcasts to the associated receiver. To send a broadcast request with permissions, specify the p...
C++11 Note: in all the following, the existence of the C++11 constant nullptr is assumed. For earlier versions, replace nullptr with NULL, the constant that used to play a similar role. Creating a pointer variable A pointer variable can be created using the specific * syntax, e.g. int *pointer_...
ActionMailer supports three callbacks before_action after_action around_action Provide these in your Mailer class class UserMailer < ApplicationMailer after_action :set_delivery_options, :prevent_delivery_to_guests, :set_business_headers Then create these methods under the private ...
public static string CreateBLOBContainer(string containerName) { try { string result = string.Empty; CloudMediaContext mediaContext; mediaContext = new CloudMediaContext(mediaServicesAccountName, mediaServicesAccou...
Sometimes conversion of primitive types to boxed types is necessary. To convert the array, it's possible to use streams (in Java 8 and above): Java SE 8 int[] primitiveArray = {1, 2, 3, 4}; Integer[] boxedArray = Arrays.stream(primitiveArray).boxed().toArray(Integer[]::new); With lowe...
With a clustered index the leaf pages contain the actual table rows. Therefore, there can be only one clustered index. CREATE TABLE Employees ( ID CHAR(900), FirstName NVARCHAR(3000), LastName NVARCHAR(3000), StartYear CHAR(900) ) GO CREATE CLUSTERED INDEX IX_Clustered O...
Non-clustered indexes have a structure separate from the data rows. A non-clustered index contains the non-clustered index key values and each key value entry has a pointer to the data row that contains the key value. There can be maximum 999 non-clustered index on SQL Server 2008/ 2012. Link for r...
When state_below is a 2D Tensor, U is a 2D weights matrix, b is a class_size-length vector: logits = tf.matmul(state_below, U) + b return tf.nn.softmax(logits) When state_below is a 3D tensor, U, b as before: def softmax_fn(current_input): logits = tf.matmul(current_input, U) + b ret...
Use tf.nn.sparse_softmax_cross_entropy_with_logits, but beware that it can't accept the output of tf.nn.softmax. Instead, calculate the unscaled activations, and then the cost: logits = tf.matmul(state_below, U) + b cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels) In this c...
Generators are functions which are able to pause and then resume execution. This allows to emulate async functions using external libraries, mainly q or co. Basically it allows to write functions that wait for async results in order to go on: function someAsyncResult() { return Promise.resolve...
Stream operations fall into two main categories, intermediate and terminal operations, and two sub-categories, stateless and stateful. Intermediate Operations: An intermediate operation is always lazy, such as a simple Stream.map. It is not invoked until the stream is actually consumed. This can...
Insert a document called 'myFirstDocument' and set 2 properties, greetings and farewell const MongoClient = require('mongodb').MongoClient; const url = 'mongodb://localhost:27017/test'; MongoClient.connect(url, function (err, db) { if (err) throw new Error(err); db.collection('myCollect...
You can use the plus (+) operator to concatenate strings: 'Dart ' + 'is ' + 'fun!'; // 'Dart is fun!' You can also use adjacent string literals for concatenation: 'Dart ' 'is ' 'fun!'; // 'Dart is fun!' You can use ${} to interpolate the value of Dart expressions within strings. The curly...
for arg; do echo arg=$arg done A for loop without a list of words parameter will iterate over the positional parameters instead. In other words, the above example is equivalent to this code: for arg in "$@"; do echo arg=$arg done In other words, if you catch yourself wri...

Page 217 of 417