You can multiply numpy arrays by scalars and it just works.
>>> import numpy as np >>> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([[1, 2, 3], [4, 5, 6]]) * 2 array([[ 2, 4, 6], [ 8, 10, 12]])
This is also a very fast and efficient operation. With your example:
>>> a_1 = np.array([1.0, 2.0, 3.0]) >>> a_2 = np.array([[1., 2.], [3., 4.]]) >>> b = 2.0 >>> a_1 * b array([2., 4., 6.]) >>> a_2 * b array([[2., 4.], [6., 8.]])
Related Posts:
- ImportError: numpy.core.multiarray failed to import
- Unable to plot Double Bar, Bar plot using pyplot for ndarray
- ImportError: numpy.core.multiarray failed to import
- ImportError: cannot import name NUMPY_MKL
- TypeError: ‘int’ object is not subscriptable
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- ImportError: DLL load failed: The specified module could not be found
- ImportError: DLL load failed: The specified module could not be found
- Import Error: No module named numpy
- ValueError: setting an array element with a sequence
- numpy max vs amax vs maximum
- TypeError: ‘int’ object is not callable
- TypeError: ‘int’ object is not callable
- What exactly does numpy.exp() do? [closed]
- TypeError: ‘int’ object is not callable
- Difference between import numpy and import numpy as np
- Cannot find module cv2 when using OpenCV
- What is the purpose of meshgrid in Python / NumPy?
- Cannot find module cv2 when using OpenCV
- why numpy.ndarray is object is not callable in my simple for python loop
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- Python ‘If not’ syntax [duplicate]
- RuntimeWarning: invalid value encountered in divide
- Converting dictionary to JSON
- Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence?
- numpy: Invalid value encountered in true_divide
- python numpy ValueError: operands could not be broadcast together with shapes
- How to fix ‘Object arrays cannot be loaded when allow_pickle=False’ for imdb.load_data() function?
- How do I create an empty array/matrix in NumPy?
- Most efficient way to find mode in numpy array
- ValueError: Unknown label type: ‘continuous’
- TypeError: unhashable type: ‘numpy.ndarray’
- How to fix IndexError: invalid index to scalar variable
- Could not install packages due to a “Environment error :[error 13]: permission denied : ‘usr/local/bin/f2py'”
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How does numpy.newaxis work and when to use it?
- WinError 2 The system cannot find the file specified (Python)
- numpy matrix vector multiplication
- Converting list to numpy array
- IndexError: tuple index out of range —– Python
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- How do I read CSV data into a record array in NumPy?
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- TypeError: cannot perform reduce with flexible type
- Could not find a version that satisfies the requirement tensorflow
- data type not understood
- How do you do natural logs (e.g. “ln()”) with numpy in Python?
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- How do I read CSV data into a record array in NumPy?
- Plotting a 2D heatmap with Matplotlib
- How to normalize a NumPy array to a unit vector?
- Should I use np.absolute or np.abs?
- Could not find a version that satisfies the requirement tensorflow
- Local variable referenced before assignment?
- ln (Natural Log) in Python
- What does numpy.random.seed(0) do?
- Factorial in numpy and scipy
- What does the c underscore expression `c_` do exactly?
- Convert pandas dataframe to NumPy array
- Python Traceback (most recent call last)
- ImportError: Missing required dependencies [‘numpy’]
- How to pip or easy_install tkinter on Windows
- Error: all the input array dimensions except for the concatenation axis must match exactly
- Cannot find module cv2 when using OpenCV
- Convert list to tuple in Python
- How to count the occurrence of certain item in an ndarray?
- size of NumPy array
- Singular matrix issue with Numpy
- Python Pandas – Missing required dependencies [‘numpy’] 1
- numpy array concatenate: “ValueError: all the input arrays must have same number of dimensions”
- How to find all occurrences of an element in a list
- How to remove \xa0 from string in Python?
- What is the meaning of [:] in python [duplicate]
- TypeError: ‘numpy.float64’ object is not callable
- TypeError: ‘numpy.float64’ object is not callable
- ‘DataFrame’ object has no attribute ‘sort’
- Convert a tensor to numpy array in Tensorflow?
- ‘DataFrame’ object has no attribute ‘sort’
- Convert a tensor to numpy array in Tensorflow?
- ValueError: all the input arrays must have same number of dimensions
- TypeError: cannot unpack non-iterable int objec
- Why are Python’s ‘private’ methods not actually private?
- ValueError: setting an array element with a sequence
- filename.whl is not a supported wheel on this platform
- Using Numpy Vectorize on Functions that Return Vectors
- Use a.any() or a.all()
- TypeError: ‘numpy.float64’ object is not callable?
- Remove list from list in Python
- How to create a new text file using Python
- ‘DataFrame’ object has no attribute ‘sort’
- Convert a tensor to numpy array in Tensorflow?
- How to normalize a NumPy array to a unit vector?
- How to raise a numpy array to a power? (corresponding to repeated matrix multiplications, not elementwise)
- TypeError: write() argument must be str, not bytes (Python 3 vs Python 2 )
- convert nan value to zero
- What is dtype(‘O’), in pandas?
- python socket.error: [Errno 98] Address already in use
- ‘End of statement expected’ in pycharm
- How to import files in python using sys.path.append?
- How can I upgrade NumPy?