Ben Chuanlong Du's Blog

It is never too late to learn.

Linked List in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

The std library of Rust has an implementation of linked list , however, it is not useful as it does not give users the flexibility of manipulating raw pointers (which is the …

Hands on Box in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Handling Complicated Data Types in Python and PySpark

Tips and Traps

  1. An element in a pandas DataFrame can be any (complicated) type in Python. To save a padnas DataFrame with arbitrary (complicated) types as it is, you have to use the pickle module . The method pandas.DataFrame.to_pickle (which is simply a wrapper over pickle.dump) serialize the DataFrame to a pickle file while the method pandas.read_pickle

Convert a Tensor to a Numpy Array or List in PyTorch

Tips

There are multiple ways to convert a Tensor to a numpy array in PyTorch. First, you can call the method Tensor.numpy.

my_tensor.numpy()

Second, you can use the function numpy.array.

import numpy as np
np.array(my_tensor)

It is suggested that you use the function numpy.array to convert a Tensor to a numpy array. The reason is that numpy.array is more generic. You can also use it to convert other objects (e.g., PIL.Image) to numpy arrays while those objects might not have a method named numpy

Collections in Kotlin

Fold vs Reduce

fold takes an initial value, and the first invocation of the lambda you pass to it will receive that initial value and the first element of the collection as parameters. reduce doesn't take an initial value, but instead starts with the first element of the collection as the accumulator (called sum in the following example).