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
18
votes
5 answers

Opencv multiply scalar and matrix

I have been trying to achieve something which should pretty trivial and is trivial in Matlab. Using methods of OpenCV, I want to simply achieve something such as: cv::Mat sample = [4 5 6; 4 2 5; 1 4 2]; sample = 5*sample; After which sample…
Arpan Shah
  • 243
  • 1
  • 3
  • 9
17
votes
2 answers

How should I convert a singleton Array to a scalar?

Let's say I have an Array variable called p: julia> p = [5] julia> typeof(p) Array{Int64,1} How should I convert it to scalar? p may also be 2-dimensional: julia> p = [1]'' julia> typeof(p) Array{Int64,2} (Note: the double transpose trick to…
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
16
votes
1 answer

Warning: Cannot use a scalar value as an array in

I am seeing the following error when executing my status script: Warning: Cannot use a scalar value as an array in $result[$array[$i*2]] = $array[$i*2+1]; What am I doing wrong? I have included the full code below:
Julian Martinez
  • 171
  • 1
  • 1
  • 5
15
votes
3 answers

opencv: convert Scalar to float or double type

Can anyone help me in converting scalar type of openCV to basic types like float or double? Scalar Sum1=sum(arg1),Sum2=sum(arg2); theta.at(i,j)=0.5*atan(Sum1/Sum2); I have to sum all elements of Mat objects arg1 and arg2 (neighbourhood sum),…
bistaumanga
  • 1,476
  • 4
  • 16
  • 23
13
votes
3 answers

List Assignment in Scalar Context

A list assignment in scalar context returns the number of elements on the right hand side: scalar(my ($hello, $there, $world) = (7,8)); #evaluates to 2 Why does it evaluate the right hand side and produce 2, instead of the newly defined list being…
Brian
  • 1,571
  • 1
  • 15
  • 20
12
votes
2 answers

Meaning of `@$array` and other constructs

I am still learning Perl 6. Please pardon my ignorance. I am reading the Operators page and I found some unfamiliar constructs at the start of a table: A Level Examples N Terms 42 3.14 "eek" qq["foo"] $x :!verbose @$array I re-read class…
lisprogtor
  • 5,677
  • 11
  • 17
11
votes
1 answer

"RuntimeError: expected scalar type Double but found Float" in Pytorch CNN training

I just begin to learn Pytorch and create my first CNN. The dataset contains 3360 RGB images and I converted them to a [3360, 3, 224, 224] tensor. The data and label are in the dataset(torch.utils.data.TensorDataset). Below is the training code. …
饼干大仙
  • 113
  • 1
  • 1
  • 5
11
votes
4 answers

What is the difference between scalar types and aggregate types in C?

I have read a book called "Pointers On C". In that book, there is a type called scalar types. I know that arithmetic types and pointer types are collectively called scalar types, but I want to know what is the difference between scalar type and…
shengfu zou
  • 560
  • 1
  • 7
  • 16
10
votes
2 answers

What is the reason to ever evaluate a hash in Perl in a scalar context?

I realize that evaluating an array in Perl in a scalar context is useful: it results in a # of elements. But what is the practical use of being able to evaluate a hash in a scalar context? e.g. my $scalar_value = %hash; scalar(%hash) As far as I…
user308378
10
votes
2 answers

adding scalar to an array in julia

Trying to get a linear equation y = m*x + c. I've the following lines of code, trying to add a scalar to an array. m = 1.1; c = 0.11; x = rand(1,2) 1×2 Array{Float64,2}: 0.920045 0.660015 y = m*x + c ERROR: MethodError: no method matching…
Van Peer
  • 2,127
  • 2
  • 25
  • 35
9
votes
6 answers

How do I multiply each member of array by a scalar in perl?

Here is the code... use strict; use warnings; my @array= (1,2,3,4,5); my $scalar= 5; @array= $scalar*@array; print @array; Need something that can perform similar function with little code. Thanks!
masterial
  • 2,166
  • 9
  • 33
  • 48
9
votes
2 answers

Objects with no '.Count' Property - use of @() (array subexpression operator) vs. [Array] cast

I am trying to perform some simple if statements, but all of the newer cmdlets that are based upon [Microsoft.Management.Infrastructure.CimInstance] don't seem to expose a .count method? $Disks = Get-Disk $Disks.Count Doesn't return anything. I…
CobyCode
  • 193
  • 5
9
votes
1 answer

In Robot Framework, what is the difference between a List Variable and a Scalar Variable containing a list?

In Robot Framework, we can assign a list to a Scalar Variable or to a List Variable, as shown below: | @{list} = | Create List | a | b | c | | ${scalar} = | Create List | a | b | c | What is the difference between a List Variable and a Scalar…
userpal
  • 1,483
  • 2
  • 22
  • 38
9
votes
2 answers

What is Perl's $; variable for?

Does any 1 have any idea what is $; (first split function argument) in the following code snippet: local(@a) = (); local($i) = 0; for ($i = 0; $i < $d; $i++) { @a = split($;, @b[$i]); $c = @a[0]; } The…
Ag.
  • 91
  • 2
9
votes
2 answers

Scalar::Util looks_like_number returning number types

I notice that looks_like_number doesn't simply return true/false as I'd assumed, but actually returns a byte indicating the type of number the perl internals say is stored in the scalar. For example: perl -e'use Scalar::Util qw/looks_like_number/;…
Oesor
  • 6,632
  • 2
  • 29
  • 56
1
2
3
35 36