by Suf | Mar 18, 2022 | Programming, Python, Tips
The built-in raw_input() function in Python 2 does not exist in Python 3. In Python 3, we can use the function input() to collect input from the user of a program If you try to use raw_input() in a Python 3 program, you will raise the NameError: name...
by Suf | Mar 18, 2022 | Programming, Python, Tips
The built-in xrange() method in Python 2 does not exist in Python 3. In Python 3, we can use the function range() to produce a range of numbers. If you try to use xrange() in a Python 3 program, you will raise the NameError: name ‘xrange’ is not defined....
by Suf | Mar 17, 2022 | Programming, Python, Tips
In Python, strings are immutable arrays of bytes representing Unicode characters. The pop() method belongs to the List data type and removes the element at the specified position. If you try to call pop() on a string, you will raise the AttributeError:...
by Suf | Mar 17, 2022 | Programming, Python, Tips
In Python, you cannot access values inside a set using indexing syntax. A set is an unordered collection of unique elements. Because a set is unordered, they do not record element position or insertion order. Therefore sets do not support indexing, slicing or other...
by Suf | Mar 16, 2022 | Programming, Python, Tips
We use lists to store multiple data values in a single variable. You cannot make a real copy of a list by typing list1 = list2, because list2 will be a reference to list1 =, and if you make changes to list1 they will be made to list2. Instead, we can use the built-in...
by Suf | Mar 14, 2022 | Programming, Python, PyTorch, Tips
To convert a NumPy array to a PyTorch tensor you can: Use the from_numpy() function, for example, tensor_x = torch.from_numpy(numpy_array)Pass the NumPy array to the torch.Tensor() constructor or by using the tensor function, for example, tensor_x =...