Tag Archives: log

Python TypeError: return arrays must be of ArrayType

from numpy import *
np.log(1.1, 2)

The above code will appear at run time

Typeerror: return arrays must be of arraytype, because the second parameter of log is not base but out array. If you just want to perform normal log operations, you can choose to use numpy.math.log (1.1, 2) or use the log function of Python’s math module

Common causes of Leetcode Runtime Error

The general reason is that it’s not initialized, it’s running as a random number;
Or it returns a wild pointer, which is common in test cases with empty sets and requires a pointer to be returned. Most of the time, it will be like this without attention:

    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
        TreeNode *result;
        if(preorder.size() == 0 && inorder.size() == 0)
            return result;
        else
            return sub_bT(0, preorder.size()-1, 0, inorder.size()-1, preorder, inorder); 

    }

At this time, we often think that a null pointer is returned, but in fact, it is not initialized. What is returned is a wild pointer, which does not know where to point to. However, when we Run Code, no error will be reported and the result is [], so we think that a null pointer is returned.

    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
        TreeNode *result(NULL);
        if(preorder.size() == 0 && inorder.size() == 0)
            return result;
        else
            return sub_bT(0, preorder.size()-1, 0, inorder.size()-1, preorder, inorder); 

    }