Questions tagged [scalar]

In computing and programming, a scalar variable or value refers to a single value, as opposed to data structures such as arrays or lists.

In computing and programming, a scalar variable refers to a single value, as opposed to data structures such as or s. A scalar can be of any type, including a complex type such as an object or string. Being scalar only means that it is manipulated as a single value.

As an example, the string type in C++ is considered to be a scalar as it is a primitive type containing a single value, although in the C language there is no such primitive type. Thus, the char array implementation of strings typically used would not be considered as a scalar.

See also:

532 questions
3
votes
4 answers

Scalar vs list context in Perl

I found an example in an O'Reilly book a little weird: @backwards = reverse qw/ yabba dabba doo /; print "list context: @backwards\n"; $backward = reverse qw/ yabba dabba doo /; print "scalar1 context: $backward\n"; $notbackward = qw/ yabba dabba…
Eric
  • 5,101
  • 10
  • 37
  • 45
3
votes
3 answers

How to convert data frame in r from positive to negative

I would like to multiply my r dataframe with minus 1, in order to reverse the signs of all values (turn + to - and vice versa): This does not work: df_neg <- df*(-1) Is there another way to do this?
Niccola Tartaglia
  • 1,537
  • 2
  • 26
  • 40
3
votes
2 answers

"Indexing" a price series to a starting time point (index level = 100) with pandas data frame : P(i,t) / P(i)

I have a pandas data frame, where datetime is the index of the data frame (I use t=0 for simplification, in fact there is something like 20170101 09:30:00) datetime Stock A Stock B t=0 5 20 t=1 6 30 t=2 …
eternity1
  • 651
  • 2
  • 15
  • 31
3
votes
4 answers

Is there a SQL Server function equivalent to AutoNumber() of QlikView?

First of all: this is not a kind of a IDENTITY() field. In QlikView, it is used to generate a number based on parameters send to function. See its documentation here:…
3
votes
1 answer

Operation returns a scalar value when a vector of values is expected

I'm evaluating a simple function: y = (2*x)/sqrt( 1 + x.^2 ); Where x is a vector with about 100 values in it. However, MATLAB makes y equal to a single scalar value in this instance. If I do: y = 2*x; I get a vector of values in y as expected. If…
bobobobo
  • 64,917
  • 62
  • 258
  • 363
3
votes
3 answers

perl: why are references to anonymous arrays scalar?

I haven't programmed in Perl in over 10 years so maybe this is something obvious to more experienced Perl programmers. I searched for an answer but didn't find anything. My question is: why are references to anonymous arrays scalar? For example in…
0xfeedbacc
  • 301
  • 2
  • 9
3
votes
2 answers

Easiest way to draw a scalar and vector field with C++?

What is the easiest, while being decently fast, way to draw a grid (say, 100 x 100) of scalar values as colors and vectors as lines from arrays of values in C++? Pure OpenGL? Something like this: I am planning on using either basic OpenGL or SDL.…
qwr
  • 9,525
  • 5
  • 58
  • 102
3
votes
1 answer

Calling 'scalar' on the results of the range operator (..) in Perl

So, I believe this has something to do with the difference between arrays and lists, but I don't understand what's going on here. Can anyone explain how and why Perl treats an expression like (1..4) differently than (1, 2, 3, 4) and @{[1..4]}? $…
user240438
3
votes
1 answer

Multiplying one matrix with a set of scalars

I have an R script that systematically perform changes to a 3x3 matrix by scalar multiplication as follows R <- matrix(rexp(9, rate=.1), ncol=3); for (i in 1:360) { K = i*R; ... } and use the modified matrix for further calculations within the…
3
votes
3 answers

c# SQL Error - Must declare scalar

I have declared the scalar already but I am still getting the error. My code checks to see if an entry exists, if it does it updates the entry or if it does not exist it creates a new entry: try { string server =…
3
votes
1 answer

OpenCV 2.4 putText() and Scalar understanding

I'm using OpenCV 2.4.11 in C++. I want to display a text with the putText() function on my picture. For example: putText(imageOutput,"x:",Point(pos[0],pos[1]),1,1,Scalar(255,0,0),2); What does the Scalar input do? Is there an alternative input…
black
  • 1,151
  • 3
  • 18
  • 46
3
votes
3 answers

Perl: How is it possible that this code is working?

my %hash = ('red' => "John", 'blue' => "Smith"); func (%hash); sub func { my $hash = $_[0]; print "$hash{'red'}\n"; print "$hash{'blue'}\n"; } I send a hash to a subroutine, and this hash is treated as scalar. If so, how is it…
user3189985
  • 189
  • 5
  • 14
3
votes
1 answer

Is there a difference between the terms "scalar" and "primitive" in Objective-C?

I'm confused on whether or not the term "scalar" means the same thing as "primitive" for Objective-C. It sounds like they mean the same thing and can be used interchangeably. I just view both as being basic C data types like BOOL, int, char, float,…
user3344977
  • 3,584
  • 4
  • 32
  • 88
3
votes
4 answers

Why does concatenation in Perl print the array's COUNT instead of the array itself

For example: my @array = ("a","b","c"); print @array; #prints abc print "Array is: " . @array #prints 3 What makes these two print statements different?
user3087867
  • 175
  • 1
  • 7
3
votes
2 answers

Simple matrix operations (2D & 3D) using Colt library

I want to perform simple matrix operations in my code and I use the Colt library (see in here: http://acs.lbl.gov/software/colt/api/index.html) I want for example to add/subtract/multiply matrices, add/subtract/multiply/divide a scalar to each cell…
Konstantinos_S
  • 65
  • 2
  • 10