Skip to content

Commit e1d037f

Browse files
authored
Merge branch 'main' into add-unordered-set-insert-doc
2 parents cc4b7ba + 4844888 commit e1d037f

File tree

4 files changed

+272
-9
lines changed

4 files changed

+272
-9
lines changed

CONTRIBUTING.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@ To link your Codecademy user profile to GitHub:
133133
- Typos/bugs
134134
- Plagiarism
135135

136-
## What is the policy for using generative AI?
137-
138-
We will not accept entries that were exclusively generated through an AI tool. We have this policy because:
139-
140-
- AI-generated content is often confidently incorrect, leading to the spread of inaccurate or misleading information.
141-
- We provide authorship credit for submissions, and to submit AI-generated work under one's own name would be a violation of our plagiarism policy.
142-
- Docs is an educational space for people to learn how to write effective technical documentation. Using generative AI, at this point, negatively impacts that desired learning goal.
143-
144136
## How do we update a PR branch?
145137

146138
To keep your PR branch up to date, navigate to the branch on your fork. Then press `Fetch upstream` and `Fetch and merge`.
@@ -158,6 +150,60 @@ git rebase upstream main
158150
git push
159151
```
160152

153+
## Can I use AI tools when contributing?
154+
155+
Yes! You can use AI tools to help create our Docs entries. [Codecademy Docs](https://github.com/Codecademy/docs) is an open-source project designed to help you learn how to contribute to open source, collaborate with the community, and use GitHub. It’s not meant to test whether you can write perfect technical content on your own.
156+
157+
AI can assist you with drafting, rewriting, or structuring content. However, you are responsible for ensuring your work meets Codecademy’s quality and [style standards](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md). AI is a tool to help you, but it doesn't replace the standards we expect.
158+
159+
You're accountable for all AI-assisted content.
160+
161+
You may use AI to generate drafts or refine your writing, but you must personally review and improve all AI-assisted content before submitting. Every entry must follow:
162+
163+
- [The Docs entry template](https://github.com/Codecademy/docs/blob/main/documentation/term-entry-template.md)
164+
- [Our content standards](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md)
165+
- [Our style guidelines](https://github.com/Codecademy/docs/blob/main/documentation/style-guide.md)
166+
167+
> **Note:** If we detect plagiarism in your entry, you will be banned from contributing to Docs.
168+
169+
## What you need to verify
170+
171+
Even if AI produced the initial version of the entry, you must ensure that:
172+
173+
- The content is accurate, technically correct, and fact-checked.
174+
- All explanations are clear and aligned with Codecademy Docs writing style.
175+
- Code examples compile or run correctly when required.
176+
- The text is not plagiarized or copied from external sources.
177+
- The final entry sounds intentional, not generic, or filled with filler text.
178+
- The formatting follows the Docs template exactly.
179+
180+
AI output often contains vague definitions, hallucinated details, or inconsistent explanations. You must correct and refine these issues before submitting a pull request.
181+
182+
## Quality standards apply to all entries
183+
184+
Regardless of how you created the content, every entry must:
185+
186+
- Use original wording.
187+
- Include accurate definitions and examples.
188+
- Follow the required structure, headings, and formatting.
189+
- Maintain a simple, educational, and neutral tone.
190+
- Avoid unnecessary complexity or overly broad explanations.
191+
- Fit the scope of a Docs reference entry.
192+
193+
> **Note:** If your submission doesn't meet these standards, we'll ask you to revise it.
194+
195+
## What happens during review?
196+
197+
Maintainers (Codecademy’s content team who reviews all contributions) may request edits on any AI-assisted entry if it:
198+
199+
- Does not follow our template.
200+
- Contains unclear, generic, or contradictory information.
201+
- Includes mistakes or technical inaccuracies.
202+
- Appears copied.
203+
- Lacks the clarity expected from Docs entries.
204+
205+
You're expected to respond to feedback and make the requested improvements within 1 week, or your PR will be closed due to inactivity.
206+
161207
Remember, if you ever have any questions at all, we're always here to help in the [Codecademy Forums](https://community.codecademy.com/).
162208

163209
If you find any bugs or errors in the content, feel free to file an issue [here](https://github.com/Codecademy/docs/issues/new?assignees=Name+here&labels=bug&template=bug_reports.yml&title=%5BBug%2FError%5D+Subject%3A+Entry+Name)! 🖖

bin/concept-of-the-week.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content/kotlin/concepts/classes/classes.md
1+
content/uiux/concepts/convergent-thinking/convergent-thinking.md
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
Title: 'byteswap()'
3+
Description: 'Swaps the byte order of each element in a NumPy ndarray.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
Tags:
8+
- 'Array'
9+
- 'Data'
10+
- 'NumPy'
11+
CatalogContent:
12+
- 'learn-python-3'
13+
- 'paths/data-science'
14+
---
15+
16+
The **`byteswap()`** method reverses the byte order of every element in a NumPy array. This is used when converting data between systems with different endianness (byte-ordering conventions). The operation either returns a new array or modifies the original one in place when `inplace=True`.
17+
18+
## Syntax
19+
20+
```pseudo
21+
ndarray.byteswap(inplace=False)
22+
```
23+
24+
**Parameters:**
25+
26+
- `inplace` (optional): When set to `True`, the byte order of the existing array is swapped in place. When `False`, a new array with swapped bytes is returned.
27+
28+
**Return value:**
29+
30+
Returns a new ndarray with swapped byte order, unless `inplace=True`, in which case the original array is modified and returned.
31+
32+
## Example 1
33+
34+
In this example, the array's byte order is swapped to convert the data into the opposite endianness:
35+
36+
```py
37+
import numpy as np
38+
39+
arr = np.array([1, 256, 1024], dtype=np.int32)
40+
41+
print("Original array:")
42+
print(arr)
43+
print("Original dtype:", arr.dtype)
44+
45+
swapped = arr.byteswap()
46+
47+
print("\nAfter byteswap():")
48+
print(swapped)
49+
print("Swapped dtype:", swapped.dtype)
50+
```
51+
52+
The output of this code is:
53+
54+
```shell
55+
Original array:
56+
[ 1 256 1024]
57+
Original dtype: int32
58+
59+
After byteswap():
60+
[16777216 65536 262144]
61+
Swapped dtype: int32
62+
```
63+
64+
## Example 2
65+
66+
This example demonstrates `byteswap(inplace=True)` and shows how the original data is altered directly:
67+
68+
```py
69+
import numpy as np
70+
71+
arr = np.array([100, 200, 300], dtype=np.int32)
72+
73+
print("Before inplace byteswap:", arr)
74+
75+
arr.byteswap(inplace=True)
76+
77+
print("After inplace byteswap:", arr)
78+
```
79+
80+
The output of this code is:
81+
82+
```shell
83+
Before inplace byteswap: [100 200 300]
84+
After inplace byteswap: [1677721600 -939524096 738263040]
85+
```
86+
87+
## Codebyte Example
88+
89+
Use the codebyte below to inspect how `byteswap()` affects a 2-D array and observe the internal memory representation change:
90+
91+
```codebyte/python
92+
import numpy as np
93+
94+
matrix = np.array([[1, 2], [3, 4]], dtype=np.int16)
95+
96+
print("Original:")
97+
print(matrix)
98+
99+
swapped = matrix.byteswap()
100+
101+
print("\nByteswapped:")
102+
print(swapped)
103+
```
104+
105+
## Frequently Asked Questions
106+
107+
### 1. What is the function of byteswap() in Python?
108+
109+
The `byteswap()` method reverses the byte order of every element in a NumPy array. It is commonly used when preparing data for systems with different endianness or when interpreting binary data from external sources.
110+
111+
### 2. What are bytes and bytearrays in Python?
112+
113+
A `bytes` object in Python is an immutable sequence of byte values, while a bytearray is a mutable version of the same concept. Both store raw binary data and are often used for file handling, networking, and low-level memory operations.
114+
115+
### 3. How to shuffle a NumPy ndarray?
116+
117+
A NumPy array can be shuffled using `np.random.shuffle()` for in-place row-wise shuffling or `np.random.permutation()` to return a shuffled copy. These functions randomize the order of elements while preserving the array’s structure.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
Title: '.logical_or()'
3+
Description: 'Computes the element-wise logical OR between two tensors.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
Tags:
8+
- 'Booleans'
9+
- 'PyTorch'
10+
- 'Tensor'
11+
CatalogContent:
12+
- 'learn-python-3'
13+
- 'paths/data-science'
14+
---
15+
16+
The **`.logical_or()`** function performs an element-wise logical OR operation between two [tensors](https://www.codecademy.com/resources/docs/pytorch/tensors). Each input value is converted to a Boolean value (zero → `False`, non-zero → `True`) before the operation. The output is a Boolean tensor where each element is `True` if at least one of the corresponding input elements is `True`.
17+
18+
## Syntax
19+
20+
```pseudo
21+
torch.logical_or(input, other, out)
22+
```
23+
24+
**Parameters:**
25+
26+
- `input`: A tensor whose elements are treated as Boolean.
27+
- `other`: A tensor broadcastable with input.
28+
- `out` (optional): A tensor to store the result.
29+
30+
**Return value:**
31+
32+
Returns a Boolean tensor where each element is `True` if at least one of the corresponding input elements is `True`.
33+
34+
## Example 1
35+
36+
In this example, `.logical_or()` evaluates pairs of values from two 2-D tensors and returns a Boolean matrix showing which positions satisfy the OR condition:
37+
38+
```py
39+
import torch
40+
41+
a = torch.tensor([[0, 1], [2, 0]])
42+
b = torch.tensor([[3, 0], [0, 5]])
43+
44+
result = torch.logical_or(a, b)
45+
46+
print("Tensor A:\n", a)
47+
print("\nTensor B:\n", b)
48+
print("\nA OR B:\n", result)
49+
```
50+
51+
The output of this code is:
52+
53+
```shell
54+
Tensor A:
55+
tensor([[0, 1],
56+
[2, 0]])
57+
58+
Tensor B:
59+
tensor([[3, 0],
60+
[0, 5]])
61+
62+
A OR B:
63+
tensor([[True, True],
64+
[True, True]])
65+
```
66+
67+
## Example 2
68+
69+
In this example, a 1-D tensor is combined with a scalar using broadcasting to show how `.logical_or()` can apply a Boolean condition efficiently across all elements:
70+
71+
```py
72+
import torch
73+
74+
x = torch.tensor([0, 4, 0, 7])
75+
y = torch.tensor(1) # scalar
76+
77+
result = torch.logical_or(x, y)
78+
79+
print(result)
80+
```
81+
82+
The output of this code is:
83+
84+
```shell
85+
tensor([True, True, True, True])
86+
```
87+
88+
## Frequently Asked Questions
89+
90+
### 1. What are the tensor operations in PyTorch?
91+
92+
Tensor operations in PyTorch include arithmetic, logical operations, reductions, reshaping, indexing, broadcasting, and matrix operations. These operations run efficiently on CPU or GPU and form the core building blocks of neural network workflows.
93+
94+
### 2. Why use tensor instead of NumPy?
95+
96+
Tensors support automatic differentiation and execute seamlessly on GPUs, which makes them suited for deep learning workloads. They also integrate tightly with PyTorch's computation graph, while NumPy arrays operate only on the CPU and lack gradient support.
97+
98+
### 3. What does cpu() do in PyTorch?
99+
100+
The `.cpu()` method moves a tensor or model from a GPU device to the system’s CPU. This is useful for running operations on hardware without CUDA support or preparing data for libraries that operate only on CPU-based arrays.

0 commit comments

Comments
 (0)