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
4
votes
1 answer

How can I assign a boolean condition result to a scalar variable in perl?

I am doing the following, but it is not working properly: my $enabled = $hash && $hash->{'key'} && $hash->{'key'}->{'enabled'} && $hash->{'key'}->{'active'}; Is this an acceptable way to…
heypano
  • 185
  • 1
  • 8
4
votes
1 answer

Writing SQL Insert Function

I'm trying to create SQL function which would add entry to a table. Before adding a new user I would like to check or this user isn't in a table already. I wrote some code, but can't save it as I get error: Invalid use of a side-effecting opreator…
Mantas
  • 85
  • 1
  • 9
4
votes
2 answers

Hibernate Criteria contains-in on an association to a table

I have a Hibernate mapping that looks something like this:
Franz See
  • 3,282
  • 5
  • 41
  • 48
4
votes
1 answer

Does anyone know what "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS" means?

Could anyone point me in the right direction, as when I save a small serialized hash via file upload to the database it works just fine, however when a large file comes along it errors out with; expected SCALAR, SEQUENCE-START, MAPPING-START, or…
dodgerogers747
  • 3,325
  • 9
  • 34
  • 55
4
votes
3 answers

Confused about whether I'm passing a scalar or an array to a subroutine in perl?

I've just started learning perl and I am am confused by this exercise (from Learning Perl Chapter 4). At the beginning of the greet() subroutine, I am trying to assign the argument $_ to my $name (my $name = $_) variable but it doesn't work. The…
gozu
  • 159
  • 5
4
votes
2 answers

Repository pattern without domain object for retrieving scalar values

Recently, I struggled trying to figure out if some methods, functions in my architecture was at the good place; in the correct layer. I want to follow the repository pattern of Martin Fowler to decouple my service layer from the database. The…
4
votes
4 answers

Is the string type a scalar, and if so why?

A few websites claim that the string type is a scalar. As I understand it, scalars are single-value types, as opposed to array types. But isn't a string essentially an array of chars? So why would it be a scalar? EDIT: If the answer/explanation…
SharpHawk
  • 378
  • 7
  • 19
3
votes
5 answers

What does this mean in perl $variable_one{$variable_two} and what is it called?

I saw this in a piece of code: if (some_condition) { $index++; } $index{$some_variable} = $index{$some_variable} + 1; What does $index{$some_variable} mean? And why is it used? Thank you. EDIT: index is defined as $index=0;
infinitloop
  • 2,863
  • 7
  • 38
  • 55
3
votes
1 answer

Error using scalar in managed object

I have some code in an app that creates a CoreData managed object. In this code, I use the following line to set a property: theAuthor.authorID = 1; The property is declared like this in the managed object header: @property (nonatomic) uint32_t…
colincameron
  • 2,696
  • 4
  • 23
  • 46
3
votes
2 answers

Perl list in boolean (scalar) context in while loop

I'm staring at this code in perl LWP::Protocol.pm and I don't understand how the loop would ever exit: while ($content = &$collector, length $$content) { $content_size += length($$content); # more here } In my interpretation, I am…
snoopyjc
  • 621
  • 4
  • 11
3
votes
1 answer

How to multiply a scalar value across multiple columns in R data.frame?

I have the following data.frame and i would like to multiply only the numeric columns by a scalar value. library(tidyverse) library(lubridate) set.seed(123) D1 <- data.frame(Date = seq(as.Date("2001-01-01"), to= as.Date("2001-01-10"), by="day"), …
Hydro
  • 1,057
  • 12
  • 25
3
votes
2 answers

Python - Turning a for-loop into a one-liner

I'm trying to create a matrix-multiplication-with-scalar function, without any libraries. It has to include list comprehension: A = [[1,2],[3,4]] # 2by2 matrix scalar = 2 #positive int product = [] for row in A: temp = [] for…
7d2672d0f4
  • 33
  • 3
3
votes
2 answers

Scalar-vector multiplication for Vector-Matrix multiplication

Is there a python (numpy) functionality that would accomplish the 3rd "equation"? using it as a returned lambda function 1. Vector * Scalar import numpy as np a = np.array([3,4]) b = 2 print(a*b) >>[6,8] or as lambda function: import numpy as…
Chris F
  • 85
  • 6
3
votes
3 answers

Perl: Length of an anonymous list

How to get the length of an anonymous list? perl -E 'say scalar ("a", "b");' # => b I expected scalar to return the list in a scalar context - its length. Why it returns the second (last) element? It works for an array: perl -E 'my @lst = ("a",…
Miroslav Popov
  • 3,294
  • 4
  • 32
  • 55
3
votes
0 answers

Getting error: only one element tensors can be converted to Python scalars

Could you please help how to solve this problem. Basically, I'm trying to get into Pytorch tensor function data that is vector not scalar. X1 and X2 are basically columns in CSV file that contains many strings. How to kind of iterate through every…
Dawid Kubicki
  • 31
  • 1
  • 3