GithubHelp home page GithubHelp logo

numpy's Introduction

Hi there ๐Ÿ‘‹

My name is Keith, and I'm an MIT trained computer scientist interested in all things Python & Data Science!

  • ๐ŸŒฑ I recently built a program to automatically download & transcribe your favorite podcasts, check it out here
  • ๐Ÿ‘ฏ Iโ€™m looking to collaborate on YouTube videos!

numpy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numpy's Issues

a few issues with the code

It seems like there are a few issues in the provided code. I will point them out and provide corrected code where needed.

  1. In the "Accessing/Changing specific elements, rows, columns, etc" section, there's an attempt to change elements of the array b using a list of lists. This will result in a ValueError. To update elements of a NumPy array, you should use the correct syntax.

  2. In the "Random Integer values" section, the function np.random.randint should be used with the low and high parameters to specify the range of random integers. The code provided is not syntactically correct.

Here's the corrected code with explanations:

import numpy as np

# The Basics
a = np.array([1, 2, 3], dtype='int32')
print(a)

b = np.array([[9.0, 8.0, 7.0], [6.0, 5.0, 4.0]])
print(b)

# Get Dimension
a.ndim

# Get Shape
b.shape

# Get Type
a.dtype

# Get Size
a.itemsize

# Get total size
a.nbytes

# Get number of elements
a.size

# Accessing/Changing specific elements, rows, columns, etc
a = np.array([[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14]])
print(a)

# Get a specific element [r, c]
a[1, 5]

# Get a specific row
a[0, :]

# Get a specific column
a[:, 2]

# Getting a little more fancy [startindex:endindex:stepsize]
a[0, 1:-1:2]

a[1, 5] = 20

# Corrected way to change elements of a NumPy array
a[:, 2] = 1  # Change the entire column to 1
print(a)

# Initializing Different Types of Arrays
np.zeros((2, 3))

np.ones((4, 2, 2), dtype='int32')

np.full((2, 2), 99)

np.random.rand(4, 2)

np.random.randint(-4, 8, size=(3, 3))

np.identity(5)

# Repeat an array
arr = np.array([[1, 2, 3]])
r1 = np.repeat(arr, 3, axis=0)
print(r1)

output = np.ones((5, 5))
print(output)

z = np.zeros((3, 3))
z[1, 1] = 9
output[1:-1, 1:-1] = z
print(output)

# Be careful when copying arrays!!!
a = np.array([1, 2, 3])
b = a.copy()
b[0] = 100
print(a)

# Mathematics
a = np.array([1, 2, 3, 4])
print(a)

a + 2

a - 2

a * 2

a / 2

b = np.array([1, 0, 1, 0])
a + b

a ** 2

np.cos(a)

# Linear Algebra
a = np.ones((2, 3))
print(a)

b = np.full((3, 2), 2)
print(b)

np.matmul(a, b)

# Statistics
stats = np.array([[1, 2, 3], [4, 5, 6]])
print(stats)

np.min(stats)

np.max(stats, axis=1)

np.sum(stats, axis=0)

I've corrected the issues in the code related to updating elements in the array and the usage of np.random.randint. The corrected code should work as expected.

Error handling

In [34]

Instead of :

replace

b[:,1,:] = [[9,9,9],[8,8]]

We use :
b[:,1,:] = [[9,9],[8,8]]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.