Skip to content

Commit fb43261

Browse files
Merge branch 'Codecademy:main' into main
2 parents 0b94a22 + 4844888 commit fb43261

File tree

8 files changed

+484
-9
lines changed

8 files changed

+484
-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/variables/variables.md
1+
content/uiux/concepts/convergent-thinking/convergent-thinking.md
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
Title: 'cbegin()'
3+
Description: 'Returns a constant iterator pointing to either the first element of the unordered set or the first element in a specific bucket.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Iterators'
9+
- 'Sets'
10+
- 'STL'
11+
CatalogContent:
12+
- 'learn-c-plus-plus'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`cbegin()`** method returns a constant iterator that points to the first element of an [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set). A constant iterator allows read-only access to elements and prevents modification. Because `unordered_set` does not maintain any defined order, the element returned by `cbegin()` depends on its internal hash table structure.
17+
18+
## Syntax
19+
20+
```pseudo
21+
unordered_set_name.cbegin(n);
22+
```
23+
24+
**Return value:**
25+
26+
Returns a `const_iterator` (constant iterator) pointing to the first element in the `unordered_set`.
27+
28+
Or, alternatively:
29+
30+
```pseudo
31+
unordered_set_name.cbegin(n);
32+
```
33+
34+
**Parameters:**
35+
36+
- `n` (size_type): The bucket index. Must be less than `bucket_count()`.
37+
38+
**Return value:**
39+
40+
A `const_local_iterator` pointing to the first element in bucket `n`. If the bucket is empty, the returned iterator equals `cend(n)`.
41+
42+
## Example
43+
44+
This example demonstrates obtaining the starting element of an `unordered_set` using `cbegin()`:
45+
46+
```cpp
47+
#include <iostream>
48+
#include <string>
49+
#include <unordered_set>
50+
using namespace std;
51+
52+
int main() {
53+
unordered_set<int> unique_numbers = {10, 5, 20, 15};
54+
55+
auto it = unique_numbers.cbegin();
56+
57+
cout << "The first element in internal order is: " << *it << "\n";
58+
59+
++it;
60+
if (it != unique_numbers.cend()) {
61+
cout << "The second element is: " << *it << "\n";
62+
}
63+
64+
// *it = 99; // Error: cannot modify through const_iterator
65+
66+
return 0;
67+
}
68+
```
69+
70+
A sample output of this code is:
71+
72+
```shell
73+
The first element in the set's internal order is: 20
74+
The second element is: 5
75+
```
76+
77+
> **Note:** Attempting to modify the element pointed to by the `const_iterator` would result in a compilation error.
78+
79+
## Codebyte Example
80+
81+
In this example, the code retrieves a constant iterator for a specific bucket in the `unordered_set` and prints all elements stored in that bucket:
82+
83+
```codebyte/cpp
84+
#include <iostream>
85+
#include <unordered_set>
86+
using namespace std;
87+
88+
int main() {
89+
unordered_set<string> words = {"cat", "dog", "rabbit", "lion"};
90+
91+
size_t bucket = 0;
92+
93+
auto it = words.cbegin(bucket);
94+
auto end = words.cend(bucket);
95+
96+
cout << "Elements in bucket " << bucket << ":\n";
97+
98+
for (; it != end; ++it) {
99+
cout << " " << *it << "\n";
100+
}
101+
102+
return 0;
103+
}
104+
```
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
Title: '.plot()'
3+
Description: 'Creates line and marker plots to visualize relationships between variables in Matplotlib.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Data Visualization'
7+
Tags:
8+
- 'Charts'
9+
- 'Matplotlib'
10+
- 'Methods'
11+
- 'Python'
12+
CatalogContent:
13+
- 'learn-python-3'
14+
- 'paths/data-science'
15+
- 'paths/data-science-foundations'
16+
---
17+
18+
The **`.plot()`** function in [Matplotlib](https://www.codecademy.com/resources/docs/matplotlib/pyplot) is the primary method used to create line plots and marker plots. It takes one or two sets of data points (x and y coordinates) and draws lines connecting them, displays markers at each point, or both. This function is one of the most commonly used tools in data visualization for showing trends, patterns, and relationships between variables.
19+
20+
Line plots are ideal for illustrating how data changes over time or across continuous intervals. It's widely used in fields such as statistics, engineering, and data science for exploratory data analysis and model visualization.
21+
22+
## Syntax
23+
24+
```pseudo
25+
matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)
26+
```
27+
28+
**Parameters:**
29+
30+
- `*args`: Values for y, or x and y, optionally followed by a format string.
31+
- `scalex`: Auto-scale the x-axis (default True).
32+
- `scaley`: Auto-scale the y-axis (default True).
33+
- `data`: Optional dict or DataFrame for referencing variables by name.
34+
- `**kwargs`: Style and configuration options like color, label, linewidth, marker.
35+
36+
**Return value:**
37+
38+
Returns a list of `Line2D` objects representing the plotted data.
39+
40+
## Example: Creating a Basic Line Plot
41+
42+
This example demonstrates how to create a simple line plot with plt.plot() to visualize the relationship between two numerical variables:
43+
44+
```py
45+
import matplotlib.pyplot as plt
46+
import numpy as np
47+
48+
# Sample data
49+
x = np.array([1, 2, 3, 4, 5])
50+
y = np.array([2, 4, 1, 6, 3])
51+
52+
# Create a line plot
53+
plt.plot(x, y)
54+
55+
# Add labels and a title
56+
plt.xlabel('X-axis')
57+
plt.ylabel('Y-axis')
58+
plt.title('Basic Line Plot Example')
59+
60+
# Add a grid for better readability
61+
plt.grid(True, linestyle='--', alpha=0.6)
62+
63+
# Display the plot
64+
plt.show()
65+
```
66+
67+
This example visualizes the relationship between an independent variable, X-axis, and a dependent variable, Y-axis, using a single continuous line. The plot shows the change in Y values as X increases from 1.0 to 5.0. This plot highlights a few useful details worth noting:
68+
69+
- Single Series: The plot displays one series of data, represented by a single blue line, showing the progression of the Y-axis value relative to the X-axis value.
70+
- Data Points and Trend: The line connects the following data points: $(1.0, 2.0)$, $(2.0, 4.0)$, $(3.0, 1.0)$, $(4.0, 6.0)$, and $(5.0, 3.0)$. The plot illustrates clear changes in direction: an initial increase, a sharp decrease, a significant increase to the maximum value, and a final decrease.
71+
- Labels and Title: The plot is clearly titled "Basic Line Plot Example" and has "X-axis" and "Y-axis" labels for clarity.
72+
- Grid: A light dashed grid is present, running horizontally and vertically across the plot, which aids in precisely reading the coordinate values of the data points off the chart.
73+
74+
![Line plot illustrating a fluctuating, piecewise linear trend between the X-axis and Y-axis, with a single blue line connecting 5 data points, a grid, and labeled axes](https://raw.githubusercontent.com/Codecademy/docs/main/media/matplot-plot-output.png)
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.

0 commit comments

Comments
 (0)