Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit 550da4e

Browse files
Merge branch 'main' into docs/css-margin-inline
2 parents 9142e2e + 8d21ec3 commit 550da4e

4 files changed

Lines changed: 306 additions & 1 deletion

File tree

bin/concept-of-the-week.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content/git/concepts/checkout/checkout.md
1+
content/kotlin/concepts/interfaces/interfaces.md
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
Title: 'Log10()'
3+
Description: 'Returns the base-10 logarithm of a specified number.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Web Development'
7+
Tags:
8+
- 'Arithmetic'
9+
- 'Functions'
10+
- 'Math'
11+
- 'Methods'
12+
CatalogContent:
13+
- 'learn-c-sharp'
14+
- 'paths/computer-science'
15+
---
16+
17+
In C#, the **`Math.Log10()`** [method](https://www.codecademy.com/resources/docs/c-sharp/methods) calculates the base-10 logarithm of a given number. This logarithm represents the power to which 10 must be raised to obtain the input value. The method is defined in the `System` namespace.
18+
19+
## Syntax
20+
21+
```pseudo
22+
Math.Log10(number);
23+
```
24+
25+
**Parameters:**
26+
27+
- `number`: A `double` value whose base-10 logarithm is computed.
28+
29+
**Return value:**
30+
31+
Returns a `double` that represents the base-10 logarithm of `number`.
32+
33+
Return values for different inputs:
34+
35+
- If the input is a positive number, the method returns its base-10 logarithm.
36+
- If the input is `0`, the method returns `NegativeInfinity`.
37+
- If the input is a negative number, the method returns `NaN`.
38+
- If the input is `NaN`, the method returns `NaN`.
39+
- If the input is `PositiveInfinity`, the method returns `PositiveInfinity`.
40+
- If the input is `NegativeInfinity`, the method returns `NaN`.
41+
42+
## Example
43+
44+
The example below demonstrates the return values of `Math.Log10()` for different inputs:
45+
46+
```cs
47+
using System;
48+
49+
class Geeks {
50+
public static void Main(String[] args) {
51+
double a = 4.55;
52+
double b = 0;
53+
double c = -2.45;
54+
double nan = Double.NaN;
55+
double positiveInfinity = Double.PositiveInfinity;
56+
double negativeInfinity = Double.NegativeInfinity;
57+
58+
Console.WriteLine(Math.Log10(a));
59+
Console.WriteLine(Math.Log10(b));
60+
Console.WriteLine(Math.Log10(c));
61+
Console.WriteLine(Math.Log10(nan));
62+
Console.WriteLine(Math.Log10(positiveInfinity));
63+
Console.WriteLine(Math.Log10(negativeInfinity));
64+
}
65+
}
66+
```
67+
68+
The output of the code is:
69+
70+
```shell
71+
0.658011396657112
72+
-Infinity
73+
NaN
74+
NaN
75+
Infinity
76+
NaN
77+
```
78+
79+
## Codebyte Example
80+
81+
This codebyte example calculates the base-10 logarithm of a given number and prints the result:
82+
83+
```codebyte/csharp
84+
using System;
85+
86+
class Program {
87+
static void Main() {
88+
double x = 10.0;
89+
double result = Math.Log10(x);
90+
91+
Console.WriteLine($"The base-10 logarithm of {x} is {result}");
92+
}
93+
}
94+
```
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
Title: 'count()'
3+
Description: 'Returns the number of elements with a specific key in an unordered_set.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Methods'
9+
- 'Sets'
10+
- 'STL'
11+
CatalogContent:
12+
- 'learn-c-plus-plus'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`count()`** [method](https://www.codecademy.com/resources/docs/cpp/methods) in C++ checks whether a given key exists in a `std::unordered_set`. Since this container stores only unique elements, `count()` will always return one of these two values:
17+
18+
- `1`: If the element is found in the set.
19+
- `0`: If the element is not found in the set.
20+
21+
This method is commonly used as a fast, _O(1)_ average time complexity way to check for element existence.
22+
23+
## Syntax
24+
25+
```pseudo
26+
unordered_set_name.count(key);
27+
```
28+
29+
**Parameters:**
30+
31+
- `key` (const Key&): The value of the element to search for. Must be of the same type as the elements stored in the `unordered_set`.
32+
33+
**Return value:**
34+
35+
Returns an integer. `1` if the element exists, `0` otherwise.
36+
37+
## Example
38+
39+
This example demonstrates using `count()` to check for the presence of elements within a set of [strings](https://www.codecademy.com/resources/docs/cpp/strings):
40+
41+
```cpp
42+
#include <iostream>
43+
#include <string>
44+
#include <unordered_set>
45+
46+
int main() {
47+
std::unordered_set<std::string> inventory = {
48+
"Sword",
49+
"Shield",
50+
"Potion"
51+
};
52+
53+
std::cout << "Inventory contains:\n";
54+
for (const auto& item : inventory) {
55+
std::cout << "- " << item << "\n";
56+
}
57+
58+
// Check for an existing element
59+
if (inventory.count("Sword")) {
60+
std::cout << "\n'Sword' is present (Count: " << inventory.count("Sword") << ").\n";
61+
}
62+
63+
// Check for a missing element
64+
if (inventory.count("Axe") == 0) {
65+
std::cout << "'Axe' is not present (Count: " << inventory.count("Axe") << ").\n";
66+
}
67+
68+
return 0;
69+
}
70+
```
71+
72+
The output of the code is:
73+
74+
```shell
75+
Inventory contains:
76+
- Potion
77+
- Shield
78+
- Sword
79+
80+
'Sword' is present (Count: 1).
81+
'Axe' is not present (Count: 0).
82+
```
83+
84+
## Codebyte Example
85+
86+
Run the codebyte below to check for the presence of an item in a set of integers:
87+
88+
```codebyte/cpp
89+
#include <iostream>
90+
#include <unordered_set>
91+
92+
int main() {
93+
std::unordered_set<int> unique_ids = {101, 205, 330};
94+
95+
int search_key = 205;
96+
int missing_key = 400;
97+
98+
// Check the count for the element 205
99+
std::cout << "Count for " << search_key << ": "
100+
<< unique_ids.count(search_key) << "\n";
101+
102+
// Check the count for the element 400
103+
std::cout << "Count for " << missing_key << ": "
104+
<< unique_ids.count(missing_key) << "\n";
105+
106+
return 0;
107+
}
108+
```
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
Title: '.logical_xor()'
3+
Description: 'Computes the element-wise logical XOR (Exclusive OR) of two input tensors.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
Tags:
8+
- 'Booleans'
9+
- 'Functions'
10+
- 'PyTorch'
11+
- 'Tensor'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/data-science'
15+
---
16+
17+
The **`.logical_xor()`** function in PyTorch computes the element-wise logical XOR (Exclusive OR) of two input [tensors](https://www.codecademy.com/resources/docs/pytorch/tensors). The resulting tensor contains Boolean (`True` or `False`) values.
18+
19+
According to the XOR rule, an element is `True` only if exactly one of the corresponding inputs is truthy. Inputs are interpreted as Boolean values where non-zero means `True` and zero means `False`.
20+
21+
## Syntax
22+
23+
```pseudo
24+
torch.logical_xor(input, other, out)
25+
```
26+
27+
**Parameters:**
28+
29+
- `input`: A Boolean tensor (or a tensor that can be cast to Boolean).
30+
- `other`: A Boolean tensor of the same shape or broadcastable to `input`.
31+
- `out` (optional): A tensor for storing the result in-place.
32+
33+
**Return value:**
34+
35+
Returns a Boolean tensor where each element is `True` when exactly one of the corresponding elements in `input` and `other` is `True`.
36+
37+
## Example 1
38+
39+
This example shows the logical XOR operation applied to two 2×2 tensors:
40+
41+
```py
42+
import torch
43+
44+
# Tensor A:
45+
# [True, False]
46+
# [True, True]
47+
tensor_a = torch.tensor([[1, 0], [5, 10]])
48+
49+
# Tensor B:
50+
# [True, True]
51+
# [False, True]
52+
tensor_b = torch.tensor([[2, 3], [0, 1]])
53+
54+
# Compute logical XOR: A XOR B
55+
# -----------------------------
56+
# [1 XOR 2] -> True XOR True -> False
57+
# [0 XOR 3] -> False XOR True -> True
58+
# [5 XOR 0] -> True XOR False -> True
59+
# [10 XOR 1] -> True XOR True -> False
60+
result_tensor = torch.logical_xor(tensor_a, tensor_b)
61+
62+
print("Tensor A:\n", tensor_a)
63+
print("\nTensor B:\n", tensor_b)
64+
print("\nA.logical_xor(B) Result (Boolean):\n", result_tensor)
65+
```
66+
67+
The output of this code is:
68+
69+
```shell
70+
Tensor A:
71+
tensor([[ 1, 0],
72+
[ 5, 10]])
73+
74+
Tensor B:
75+
tensor([[2, 3],
76+
[0, 1]])
77+
78+
A.logical_xor(B) Result (Boolean):
79+
tensor([[False, True],
80+
[ True, False]])
81+
```
82+
83+
## Example 2
84+
85+
This example demonstrates XOR on two 1-D tensors so each result maps cleanly to a single pair of elements:
86+
87+
```py
88+
import torch
89+
90+
x = torch.tensor([1, 0, 10, 0])
91+
y = torch.tensor([0, 5, 0, 0])
92+
93+
# Compute x XOR y
94+
xor_result = torch.logical_xor(x, y)
95+
96+
print(xor_result)
97+
```
98+
99+
The output of this code is:
100+
101+
```shell
102+
tensor([ True, True, True, False])
103+
```

0 commit comments

Comments
 (0)