# numpy

## Why is this JAX jitted function so much slower than the non-jitted JAX version?

Why is this JAX jitted function so much slower than the non-jitted JAX version? Question: I’m in the process of rewriting some code from pure Python to JAX. I have a function that I need to call a lot. Why is the jitted version of the following function so much slower than the non-jitted version? …

## Row by row multiplication on pandas or numpy

Row by row multiplication on pandas or numpy Question: I have one dataframe with classes and two components and a second one with elements and the same components. df1: df1 = pd.DataFrame({‘Class’:[‘banana’, ‘apple’], ‘comp1’:[1, 2], ‘comp2’:[-5, 4]}) df2: df2 = pd.DataFrame({‘Element’:[‘K’, ‘Mg’], ‘comp1’:[3, -4], ‘comp2’:[1, 3]}) I want to multiply them row by row in …

## How to get linear value from Dataframe

How to get linear value from Dataframe Question: I have simple question. i want to get linear value with dataframe.(like N-D Lookuptable in Matlab simulink) type python import numpy as np import scipy as sp import pandas as pd X = np.array([100,200,300,400,500]) Y = np.array([1,2,3]) W = np.array([[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3]]) df = pd.DataFrame(W,index=Y,columns=X) # 100 200 300 …

## how to accelerate the numpy for-loop, for coloring point-cloud by its intensity

how to accelerate the numpy for-loop, for coloring point-cloud by its intensity Question: enter code hereI want to color a point-cloud by its intensity. currently I use the following for-loop to apply a colormap function to the intensity(4th-dim) of points: import numpy as np points = np.random.random([128*1200,4]) points_colors = np.zeros([points.shape[0], 3]) for idx, p_c in …

## subset fail on np.meshgrid generated dataframe

subset fail on np.meshgrid generated dataframe Question: I generate a dataframe for lonlat like this a=np.arange(89.7664, 89.7789, 1e-4) b=np.arange(20.6897, 20.7050, 1e-4) temp_arr=np.array(np.meshgrid(a, b)).T.reshape(-1, 2) np_df=pd.DataFrame(temp_arr, columns = [‘lon’,’lat’]) and it create the dataframe I want When I tried to subset the first lon len(np_df[np_df[‘lon’]==89.7664]) it will return 153. But when I tried subset some last …

## ValueError: shapes (3,) and (4,) not aligned: 3 (dim 0) != 4

ValueError: shapes (3,) and (4,) not aligned: 3 (dim 0) != 4 Question: import numpy as np inputs = [1, 2, 3, 2.5] weights = [ [0.2, 0.8, -0.5, 1.0], [0.5 -0.91, 0.26, -0.5], [-0.26, -0.27, 0.17, 0.87]] biases = [2, 3, 0.5] output = np.dot(weights, inputs) + biases print(output) I’m very new to numpy, …

## Type hint for numpy.ndarray containing unsignedinteger

Type hint for numpy.ndarray containing unsignedinteger Question: I have a numpy array that contains unsignedinteger, something like this: arr = np.uint16([5, 100, 2000]) array([ 5, 100, 2000], dtype=uint16) This arr will be input to a function. I am wondering how the type hint of the function argument should look like? def myfunc(arr: ?): pass I …

## Multiprocessing freeze_support() error in Python

Multiprocessing freeze_support() error in Python Question: I am new to deep learning concept and has been using google colab to run the deep learning models till now. And while i was trying the same with pycharm this error shows up. Project_name=model,file_name=model.py from __future__ import print_function, division import torch import torch.nn as nn import torch.optim as …